Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GDI+ Bitmaps

GDI+ Bitmaps

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformsgame-devhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jgeorge21
    wrote on last edited by
    #1

    In my quest for a simple to use image loading library I came across GDI+. I only want to use the portion of GDI+ that loads images, since it loads every image type that I would ever need into a DIB (which I can extract and feed OpenGL). However, I have the most annoying and frustrating issue: the image is not loaded and the lastResult member of the Bitmap object indicates InvalidParameter. Obviously I'm feeding it something bad. The relevant code snippet follows: xBoolean xImage::Load (char *fileName, xBoolean mipmap) { BitmapData *bmpData = new BitmapData (); Rect *rect = new Rect (); sint32 format, stride; uint32 i, j; xbyte *tempBuffer; uint32 wideLen; WCHAR *fileNameW = NULL; if (fileName == NULL) // Early out if string is NULL return xfalse; // Convert C string to UNICODE wideLen = MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, fileName, -1, NULL, 0); // Get necessary length fileNameW = (WCHAR *)malloc (wideLen); // Alloc string MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, fileName, -1, fileNameW, wideLen); // Translate string Bitmap bmp ((const WCHAR *)fileNameW, FALSE); ... The string fileName is being properly translated to fileNameW as below: // Original String fileName[0] 119 'w' char fileName[1] 104 'h' char fileName[2] 105 'i' char fileName[3] 116 't' char fileName[4] 101 'e' char fileName[5] 46 '.' char fileName[6] 116 't' char fileName[7] 103 'g' char fileName[8] 97 'a' char fileName[9] 0 char // Wide String fileNameW[0] 119 unsigned short fileNameW[1] 104 unsigned short fileNameW[2] 105 unsigned short fileNameW[3] 116 unsigned short fileNameW[4] 101 unsigned short fileNameW[5] 46 unsigned short fileNameW[6] 116 unsigned short fileNameW[7] 103 unsigned short fileNameW[8] 97 unsigned short fileNameW[9] 0 unsigned short The constructor for the Bitmap object is as follows: class Bitmap : public Image { public: friend class Image; friend class CachedBitmap; Bitmap( IN const WCHAR *filename, IN BOOL useEmbeddedColorManagement = FALSE ); Recall that the lastResult member is being set to InvalidParameter. Here are the possible GDI+ return values: enum Status { Ok = 0, GenericError = 1, InvalidParameter = 2, OutOfMemory = 3, ObjectBusy = 4, InsufficientBuffer = 5, NotImplemented = 6, Win32Error = 7, WrongState = 8, Aborted = 9, FileNotF

    PJ ArendsP 1 Reply Last reply
    0
    • J jgeorge21

      In my quest for a simple to use image loading library I came across GDI+. I only want to use the portion of GDI+ that loads images, since it loads every image type that I would ever need into a DIB (which I can extract and feed OpenGL). However, I have the most annoying and frustrating issue: the image is not loaded and the lastResult member of the Bitmap object indicates InvalidParameter. Obviously I'm feeding it something bad. The relevant code snippet follows: xBoolean xImage::Load (char *fileName, xBoolean mipmap) { BitmapData *bmpData = new BitmapData (); Rect *rect = new Rect (); sint32 format, stride; uint32 i, j; xbyte *tempBuffer; uint32 wideLen; WCHAR *fileNameW = NULL; if (fileName == NULL) // Early out if string is NULL return xfalse; // Convert C string to UNICODE wideLen = MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, fileName, -1, NULL, 0); // Get necessary length fileNameW = (WCHAR *)malloc (wideLen); // Alloc string MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, fileName, -1, fileNameW, wideLen); // Translate string Bitmap bmp ((const WCHAR *)fileNameW, FALSE); ... The string fileName is being properly translated to fileNameW as below: // Original String fileName[0] 119 'w' char fileName[1] 104 'h' char fileName[2] 105 'i' char fileName[3] 116 't' char fileName[4] 101 'e' char fileName[5] 46 '.' char fileName[6] 116 't' char fileName[7] 103 'g' char fileName[8] 97 'a' char fileName[9] 0 char // Wide String fileNameW[0] 119 unsigned short fileNameW[1] 104 unsigned short fileNameW[2] 105 unsigned short fileNameW[3] 116 unsigned short fileNameW[4] 101 unsigned short fileNameW[5] 46 unsigned short fileNameW[6] 116 unsigned short fileNameW[7] 103 unsigned short fileNameW[8] 97 unsigned short fileNameW[9] 0 unsigned short The constructor for the Bitmap object is as follows: class Bitmap : public Image { public: friend class Image; friend class CachedBitmap; Bitmap( IN const WCHAR *filename, IN BOOL useEmbeddedColorManagement = FALSE ); Recall that the lastResult member is being set to InvalidParameter. Here are the possible GDI+ return values: enum Status { Ok = 0, GenericError = 1, InvalidParameter = 2, OutOfMemory = 3, ObjectBusy = 4, InsufficientBuffer = 5, NotImplemented = 6, Win32Error = 7, WrongState = 8, Aborted = 9, FileNotF

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      jgeorge21 wrote: fileName[5] 46 '.' char fileName[6] 116 't' char fileName[7] 103 'g' char fileName[8] 97 'a' char From MSDN: [quote] Bitmap::Bitmap(filename, useIcm) Creates a Bitmap object based on an image file. Bitmap( const WCHAR* filename, BOOL useIcm ); Parameters filename [in] Pointer to a null-terminated string that specifies the path name of the image file. The graphics file formats supported by GDI+ are BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF. [/quote] I do not see tga in the list of supported formats. Try http://www.codeproject.com/bitmap/cximage.asp[^] instead.


      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


      Honoured as one of The Most Helpful Members of 2004

      Within you lies the power for good; Use it!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups