954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Assign bitmap to image through constructor

It may seem like a simple answer, but how do I pass an image to a bitmaps constructor.
for example:

Bitmap bmp = new Bitmap(########);


what would I put in place of the pound signs If i wanted the default image to be

C://Users/Me/Documents/Visual Studio 2010/Projects/MyProject/Image.jpg

Please help.

jackabascal
Newbie Poster
13 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

It may seem like a simple answer, but how do I pass an image to a bitmaps constructor. for example:

Bitmap bmp = new Bitmap(########);

what would I put in place of the pound signs If i wanted the default image to be

C://Users/Me/Documents/Visual Studio 2010/Projects/MyProject/Image.jpg

Please help.

From MSDN:
A bitmap consists of the pixel data for a graphics image and its attributes. There are many standard formats for saving a bitmap to a file. GDI+ supports the following file formats: BMP, GIF, EXIF, JPG, PNG and TIFF.

// Retrieve the image.
    myImage = new Bitmap(@"<put your path here>", true);
Zinderin
Junior Poster in Training
76 posts since Jun 2010
Reputation Points: 22
Solved Threads: 8
 

I would generally advise against using literal file paths (eg C:/Users/You/MyDocuments/etc) because you can't guarantee the file structure on every machien that runs your code.
Either add the image as an embedded resource and access it from there or add it to your project as content so that it is in the same directory as your executable and you can access it by name.

Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: