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(&ci nfo);
jpeg_stdio_src(&cinfo, arq);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cin fo);
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(&ci nfo);
jpeg_destroy_decompress(&c info);
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!
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(&ci
jpeg_stdio_src(&cinfo, arq);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cin
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
}
jpeg_finish_decompress(&ci
jpeg_destroy_decompress(&c
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
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!!
ASKER
Thanks a lot you solve a huge problem for me... thanks a lot!