By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,572 Members | 1,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,572 IT Pros & Developers. It's quick & easy.

Question on how to access bitmap: Public Function getBitmap() As Bitmap

P: n/a
At the risk of being publically humiliated, might I ask the following
simple question.

I have a solution with one project. This project, WindowsApplication1,
has one "form" and one "bitmap" (the bitmap created by right clicking
on the project, selecting add new item, then add bitmap file). The
project explorer says my bitmap is called "Bitmap1.bmp".

If I have a function in my project declared as

Public Function getBitmap() As Bitmap

How do I return this bitmap using this function?

I have looked at the the contructor for "Bitmap" and it has 12
versions, one of which is to pass the filename. I don't want to do
this because then it says my bitmap has to be in a certain location on
the disk - I just want to reference the bitmap already in the project
but can't see how to do it without needing to know the filename
(either directly or through a stream or input reader).
So am I missing something and it isn't easy?
Thank you
Michael
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Dim objBitmap as bitmap

objBitmap = New Bitmap
(System.Reflection.Assembly.GetExecutingAssembly.G etManife
stResourceStream("WindowsApplication1.Bitmap1.bmp" ))

'what the code does is the following
'opens the application
'creates a stream to read the resource
'reads the resource belonging to
namespace 'WindowsApplication1' named 'Bitmap1.bmp'

Ensure that the resources is not simply added to the
project, but an EMBEDDED RESOURCE (right click on the bmp
file in solution explorer, properties, and ensure it's
embedded).

Regards
Nov 20 '05 #2

P: n/a
Thanks a lot. This worked fine. But ... and there's always a but, it
means I have to include a string literal
"WindowsApplication1.Bitmap1.bmp" to reference the bitmap. I would
rather refer to it by a name, so that if the name changed in one place
and not another, the /*compiler/* would not let the program compile.
The way it is coded here means that if I changed my window application
name, or changed the bitmap name from say "Bitmap1.bmp" to
"SendButton.bmp", it mightn't work anymore (unless me, or everyone
else modifying my program, also remembered to change it everywhere
carefully). Can you reference the bitmap resource by a name?
Thank you
Michael

"anonymous" <an*******@anonymous.com> wrote in message news:<02****************************@phx.gbl>...
Dim objBitmap as bitmap

objBitmap = New Bitmap
(System.Reflection.Assembly.GetExecutingAssembly.G etManife
stResourceStream("WindowsApplication1.Bitmap1.bmp" ))

'what the code does is the following
'opens the application
'creates a stream to read the resource
'reads the resource belonging to
namespace 'WindowsApplication1' named 'Bitmap1.bmp'

Ensure that the resources is not simply added to the
project, but an EMBEDDED RESOURCE (right click on the bmp
file in solution explorer, properties, and ensure it's
embedded).

Regards

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.