Icons and Bitmap resources, How do you refer to them? 
Author Message
 Icons and Bitmap resources, How do you refer to them?

I know that you can refer to VBNet forms by creating a reference to the
forms object:
System.Windows.Forms.MyForm

How do you refer to an imbedded Icon or Bitmap in your project? I want to
create an object reference to an Icon or Bitmap. It's got to be really easy
and I've got to be really thick. Any help would be appreciated.

'Not Me.Icon but a reference to an Icon or Bitmap that's been added to my
project
Dim icn As Icon = ???



Mon, 31 Jan 2005 04:22:16 GMT  
 Icons and Bitmap resources, How do you refer to them?
Hi Mark,

Basic idea is to read the embedded icon or bitmap into a Stream. Here's some
code from my book that allows the user to select from a list of embedded
images, read the image into a Bitmap, and then show it in a PictureBox:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As _
 System.EventArgs) Handles ComboBox1.SelectedIndexChanged

 Dim streamName As String = ComboBox1.Text
 Dim streamID As System.IO.Stream

 If streamName.IndexOf(".bmp") > 0 Then
  Try
   streamID = Me.GetType.Assembly.GetManifestResourceStream(streamName)
   Dim bitmapID As Bitmap = New Bitmap(streamID)
   With PictureBox4
    .Size = bitmapID.Size
    .Image = bitmapID
   End With
  Catch Ex As Exception
   MessageBox.Show(Ex.Message)
  Finally
   If Not IsNothing(streamID) Then
    streamID.Close()
   End If
  End Try
 Else
  MessageBox.Show(streamName & " is not a Bitmap resource.", "Not a Bitmap",
_
   MessageBoxButtons.OK, MessageBoxIcon.Information)
 End If
End Sub

Hope this is helpful.

--
Jeff Rhodes
Author of "VBTrain.Net: Creating Computer and Web Based Training with Visual
Basic? .NET"
www.vbtrain.net
Home of the Shape and Graphical Text controls


Quote:
> I know that you can refer to VBNet forms by creating a reference to the
> forms object:
> System.Windows.Forms.MyForm

> How do you refer to an imbedded Icon or Bitmap in your project? I want to
> create an object reference to an Icon or Bitmap. It's got to be really
easy
> and I've got to be really thick. Any help would be appreciated.

> 'Not Me.Icon but a reference to an Icon or Bitmap that's been added to my
> project
> Dim icn As Icon = ???



Tue, 01 Feb 2005 00:57:41 GMT  
 Icons and Bitmap resources, How do you refer to them?
Jeff, I'm sure you can help a bit, if you may ...

I have a very simple app. into which I "include" a number of images...
I want to get to these images using the following:

Dim ImageStream as Stream =
[Assemby].GetExecutingAssembly.GetManifestResourceStream("MyApp.MyImage.bmp"
)

I know NOTHING about assemblies. I find the documentation talking in circles
and need a VERY simple example. All I want to do is retrieve the images that
are
compiled into the exe.

Please give a simple example/explanation on editing the AssemblyInfo.vb file
AND/OR any code that will ultimately allow me to use my above code sample
... unless
you have another way of extracting an "included" image from the compiled
exe...

Thanks,

LM


Quote:
> Hi Mark,

> Basic idea is to read the embedded icon or bitmap into a Stream. Here's
some
> code from my book that allows the user to select from a list of embedded
> images, read the image into a Bitmap, and then show it in a PictureBox:

> Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
> ByVal e As _
>  System.EventArgs) Handles ComboBox1.SelectedIndexChanged

>  Dim streamName As String = ComboBox1.Text
>  Dim streamID As System.IO.Stream

>  If streamName.IndexOf(".bmp") > 0 Then
>   Try
>    streamID = Me.GetType.Assembly.GetManifestResourceStream(streamName)
>    Dim bitmapID As Bitmap = New Bitmap(streamID)
>    With PictureBox4
>     .Size = bitmapID.Size
>     .Image = bitmapID
>    End With
>   Catch Ex As Exception
>    MessageBox.Show(Ex.Message)
>   Finally
>    If Not IsNothing(streamID) Then
>     streamID.Close()
>    End If
>   End Try
>  Else
>   MessageBox.Show(streamName & " is not a Bitmap resource.", "Not a
Bitmap",
> _
>    MessageBoxButtons.OK, MessageBoxIcon.Information)
>  End If
> End Sub

> Hope this is helpful.

> --
> Jeff Rhodes
> Author of "VBTrain.Net: Creating Computer and Web Based Training with
Visual
> Basic? .NET"
> www.vbtrain.net
> Home of the Shape and Graphical Text controls



> > I know that you can refer to VBNet forms by creating a reference to the
> > forms object:
> > System.Windows.Forms.MyForm

> > How do you refer to an imbedded Icon or Bitmap in your project? I want
to
> > create an object reference to an Icon or Bitmap. It's got to be really
> easy
> > and I've got to be really thick. Any help would be appreciated.

> > 'Not Me.Icon but a reference to an Icon or Bitmap that's been added to
my
> > project
> > Dim icn As Icon = ???



Wed, 09 Feb 2005 02:25:36 GMT  
 Icons and Bitmap resources, How do you refer to them?

Quote:
> Jeff, I'm sure you can help a bit, if you may ...

> I have a very simple app. into which I "include" a number of
> images... I want to get to these images using the following:

> Dim ImageStream as Stream =

[Assemby].GetExecutingAssembly.GetManifestResourceStream("MyApp.MyImage.bmp"

Quote:
> )

> I know NOTHING about assemblies. I find the documentation
> talking in circles and need a VERY simple example.

The simplest explanation: An assembly is an EXE or DLL file.

Quote:
> All I want to
> do is retrieve the images that are
> compiled into the exe.

> Please give a simple example/explanation on editing the
> AssemblyInfo.vb file AND/OR any code that will ultimately allow
> me to use my above code sample ... unless
> you have another way of extracting an "included" image from the
> compiled exe...

Your code already creates an ImageStream. "MyApp.MyImage.bmp" consists of
the default namespace ("MyApp") of the project (see project's properties)
and the name of a bmp file ("myimage.bmp") that you can add to the project.
Select the bitmap file in solution explorer, open the property window and
set the buildaction property to "embedded resource"

After the Imagestream has been created, create a new bitmap from the stream:
dim bmp as bitmap
bmp = new bitmap(ImageStream)

Armin



Wed, 09 Feb 2005 03:56:25 GMT  
 Icons and Bitmap resources, How do you refer to them?
Armin, got it working using this:

Dim ImageStream As Stream =
Me.GetType.Assembly.GetExecutingAssembly.GetManifestResourceStream("Myapp.My
Image.tif")

Thanks for your help!

LM


Quote:

> > Jeff, I'm sure you can help a bit, if you may ...

> > I have a very simple app. into which I "include" a number of
> > images... I want to get to these images using the following:

> > Dim ImageStream as Stream =

[Assemby].GetExecutingAssembly.GetManifestResourceStream("MyApp.MyImage.bmp"
Quote:
> > )

> > I know NOTHING about assemblies. I find the documentation
> > talking in circles and need a VERY simple example.

> The simplest explanation: An assembly is an EXE or DLL file.

> > All I want to
> > do is retrieve the images that are
> > compiled into the exe.

> > Please give a simple example/explanation on editing the
> > AssemblyInfo.vb file AND/OR any code that will ultimately allow
> > me to use my above code sample ... unless
> > you have another way of extracting an "included" image from the
> > compiled exe...

> Your code already creates an ImageStream. "MyApp.MyImage.bmp" consists of
> the default namespace ("MyApp") of the project (see project's properties)
> and the name of a bmp file ("myimage.bmp") that you can add to the
project.
> Select the bitmap file in solution explorer, open the property window and
> set the buildaction property to "embedded resource"

> After the Imagestream has been created, create a new bitmap from the
stream:
> dim bmp as bitmap
> bmp = new bitmap(ImageStream)

> Armin



Wed, 09 Feb 2005 11:12:13 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Resource questions (icon, bitmap, string, etc.)

2. Icon/Bitmap Resource via DCOM

3. How to extract a bitmap given a file name and bitmap resource ID

4. How to extract a bitmap given a file name and bitmap resource ID

5. Referring to controls - What am I doing wrong???

6. Referring to controls - What am I doing wrong???

7. doing transitions to a bitmap..hotw to?

8. Dialog resources in VB5 - Can it be done?

9. Loading bitmap resource to Picture control

10. Q (VB5) : Imaglist or Bitmap Resource File

11. Q (VB5) : Bitmap Resource File or Imagelists?

12. Loading bitmap as resource from DLL

 

 
Powered by phpBB® Forum Software