Solved

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

Posted on 2004-08-10
3
667 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 250 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 250 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now