Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

cant get bitmap to be used as embedded resource, code supplied

Posted on 2004-08-10
3
Medium Priority
?
680 Views
Last Modified: 2013-12-03
hi, i cant get 2 bitmaps to be seen as embedded resources.
i copied the bitmaps out of syncfusions datagridbuttons demo.
i added them by  using the solution explorer > add existing item.
i also tried adding them by File > Add Existing item
i set the files' build action to embedded resource.
i also tried the build action on content.
i have spent a lot of time on this and its as if theres a connection i need to make before it can see
the files as embedded resources. i did compile it first before i ran it in debug mode.
i just get the error

An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll
Additional information: 'null' is not a valid value for 'stream'.

in this section:
  Dim streamBitMap As System.IO.Stream = assemblyExecution.GetManifestResourceStream(BitMapName)
  Dim bitmapEmbedded As Bitmap = New Bitmap(streamBitMap)

here is all the code, you need 2 bitmaps, one called buttonface.bmp and buttonfacepressed.bmp
but its all available at www.tapeus.co.za/download/eeicon.zip

Public Class Form1
    Inherits System.Windows.Forms.Form
    Private WithEvents Icons As ImageList
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private _buttonFace As Bitmap
    Private _buttonFacePressed As Bitmap

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Attempt1()
        Attempt2()
    End Sub
    Private Sub Attempt1()
        Dim strm As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("buttonface.bmp")
        _buttonFace = New Bitmap(strm)
        strm = Me.GetType().Assembly.GetManifestResourceStream("buttonfacepressed.bmp")
        _buttonFacePressed = New Bitmap(strm)
    End Sub
    Private Sub Attempt2()
        _buttonFace = GetEmbeddedBitmap("buttonface.bmp")
        _buttonFacePressed = GetEmbeddedBitmap("buttonfacepressed.bmp")
    End Sub
    Public Function GetEmbeddedBitmap(ByVal BitMapName As String) As Bitmap
        Dim assemblyExecution As System.Reflection.Assembly = Me.GetType.Assembly.GetEntryAssembly()
        Dim namespaceName As String = assemblyExecution.GetName().Name.ToString()
        BitMapName = namespaceName & "." & BitMapName
        Dim streamBitMap As System.IO.Stream = assemblyExecution.GetManifestResourceStream(BitMapName)
        Dim bitmapEmbedded As Bitmap = New Bitmap(streamBitMap)
        Return bitmapEmbedded
    End Function
End Class
0
Comment
Question by:jxharding
  • 2
3 Comments
 
LVL 27

Assisted Solution

by:planocz
planocz earned 1000 total points
ID: 11762079
Use with a image list
  Private Sub InitializeIcons()
        Dim executing_assembly As System.Reflection.Assembly = Me.GetType.Assembly.GetEntryAssembly()
        ' Get the namespace.
        Dim my_namespace As String = executing_assembly.GetName().Name.ToString()
        Me.ImageList1.Images.AddStrip(Image.FromStream(Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(my_namespace +" MYbmp.bmp")))
    End Sub
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11763186
Hi jxharding,

Your attemps where correct, you just forgot to set the build action for your bitmaps to embedded resource.
Right click on your bitmap choose properties and set the build action to embedded resource
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 1000 total points
ID: 11763221
I just tried it with this code and it works perfectly

    Private Sub Attempt1()
        Dim CurrentAssembly As Reflection.Assembly = _
        Reflection.Assembly.GetExecutingAssembly
        Dim BitMapStream As IO.Stream = _
        CurrentAssembly.GetManifestResourceStream( _
        "WindowsApplication3.smiley.BMP")
        Dim SmileyBitmap As Drawing.Bitmap = New Bitmap(BitMapStream)
        PictureBox1.Image = SmileyBitmap
    End Sub

if you try this without setting the build action to embedded resource you will get your error

An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll
Additional information: 'null' is not a valid value for 'stream'.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question