我在寫一個基於Win32的應用程序,它顯示來自數據庫的jpeg圖像。我選擇了libjpeg作爲解碼器,但大多數圖像顯示不正確。它可以通過增加或減少圖像的寬度來固定,但是,在修復之後顯示不正確之前已正確顯示的圖像。這裏的(不包括RGB到BGR轉換)我的代碼部分:libjpeg/CreateDIBSection問題
int JpegToRaw(BYTE *input, int insize, BYTE *output, int &width, int &height)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, input, insize);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
//--cinfo.output_width; or ++cinfo.output_width;
int row_stride = cinfo.output_width * 3;
int outsize = row_stride * cinfo.output_height;
output = (BYTE *)malloc(outsize * sizeof(BYTE));
BYTE *pos = output;
while (cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo, &pos, 1);
pos += row_stride;
}
width = cinfo.output_width;
height = cinfo.output_height;
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
return outsize;
}
HBITMAP RawToBitmap(BYTE *input, int size, int width, int height)
{
BITMAPINFO bi;
bi.bmiHeader.biSize = sizeof(bi24BitInfo.bmiHeader);
bi.bmiHeader.biWidth = width;
bi.bmiHeader.biHeight = -height;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biCompression = BI_RGB;
HBITMAP hBitmap = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, NULL, NULL, 0);
SetBitmapBits(hBitmap, size, input);
return hBitmap;
}
我敢肯定,我通過有效的JPEG陣列JpegToRaw()
,但我不知道爲什麼在圖片顯示不同。有人可以幫助我得到它嗎?
我不敢相信我可以忽略這個重要的事實!非常感謝! – Joulukuusi 2011-03-19 00:53:52