Solved

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

Posted on 2004-08-10
3
673 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…

738 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