Link to home
Start Free TrialLog in
Avatar of richardomus
richardomus

asked on

Convert an RGB BYTE* array to BITMAP ... How?

Hello all!!
First i have to thanks for any help on this...

Well, my problem is making my head burn... I have an routine that decompress an jpeg file to an BYTE* array and returning it...

BYTE* jpeg_LoadJpeg(const char* filename)
 {
   FILE* arq = fopen(filename,"rb");
   if(arq == NULL) return NULL;

   struct jpeg_decompress_struct cinfo;
   struct  jpeg_error_mgr jerr;
   BYTE *linha;
   BYTE *image;
   int ImageSize;

   cinfo.err = jpeg_std_error(&jerr);
   jpeg_create_decompress(&cinfo);

   jpeg_stdio_src(&cinfo, arq);
   jpeg_read_header(&cinfo, TRUE);
   jpeg_start_decompress(&cinfo);
   
   ImageSize = cinfo.image_width * cinfo.image_height * 3;
   image = new BYTE[ImageSize];
   linha=image;
   
   while (cinfo.output_scanline < cinfo.output_height)
    { linha = image + 3 * cinfo.image_width * cinfo.output_scanline;
      jpeg_read_scanlines(&cinfo,&linha,1);
     }
     
   jpeg_finish_decompress(&cinfo);
   jpeg_destroy_decompress(&cinfo);

   fclose (arq);
   return image;
 }

ok, it works fine, and i have the jpeg file returned in an BYTE* array of size X*Y*3.... now, i want to transform this array into an BITMAP, HBITMAP, or whatever, so i can display it on my HWND device context, or associate it to my HWND static control to show it on screen...

how can i transform this array of bytes, that contain my RGB values of my jpeg file so i can display then on my window screen?

thanks a lot!
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of richardomus
richardomus

ASKER

I love you man!!!!

Thanks a lot you solve a huge problem for me... thanks a lot!
Opsss ... there is still a problem... the image apeears "blue", and not in real colors... but the arry is ok, i plot it before with SetPixel and the colors was fine... whats happening?
Windows Bitmap keeps colors in BGR order. If image returned by jpeg_LoadJpeg function has RGB order, you need to swap R and B bytes in it.
wow... your right... i did a loop to swap the R and B and it works fine... why windows keep on this strange format? why not commom RGB sequence? anyway, thanks a lot!!