none
Load a bitmap from resources

    Question

  • Hi !

    How can I load an image (bitmap) from bitmap already added in resources?

    I am using loadimage() function to load from file and I am looking for similar functions (same technolgy) to load the image from resources.

    Any idea please?!

    Tuesday, August 25, 2009 2:21 PM

Answers

  • LoadImage() can do this too, just omit the LR_LOADFROMFILE option.  The lpszName argument must be the resource name or ID.

    Hans Passant.
    • Marked as answer by yade Thursday, August 27, 2009 7:47 AM
    Tuesday, August 25, 2009 3:13 PM
    Moderator
  • The LoadBitmap() function can be used too
    • Marked as answer by yade Thursday, August 27, 2009 7:47 AM
    Tuesday, August 25, 2009 9:59 PM

All replies

  • You want to use Assembly.GetManifestResourceStream to create a Stream to your Bitmap data.  You can then create the bitmap directly from this stream.

    This will look like:

    Stream bitmapData = Assembly.GetExecutingAssembly().GetManifestResourceStream("myImage.bmp");
    Bitmap bitmap = new Bitmap(bitmapData);


    For full details, see the MSDN page on Embedding Image Resources .
    Reed Copsey, Jr. - http://reedcopsey.com
    Tuesday, August 25, 2009 3:12 PM
  • LoadImage() can do this too, just omit the LR_LOADFROMFILE option.  The lpszName argument must be the resource name or ID.

    Hans Passant.
    • Marked as answer by yade Thursday, August 27, 2009 7:47 AM
    Tuesday, August 25, 2009 3:13 PM
    Moderator
  • The LoadBitmap() function can be used too
    • Marked as answer by yade Thursday, August 27, 2009 7:47 AM
    Tuesday, August 25, 2009 9:59 PM