Click here to Skip to main content
15,897,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get a 24-Bit bitmap and display it into a Picture Box.I find 2 ways to solve this question but both failed.
Please help me!


There is a 'Picture Control' whose type is Bitmap in a dialog.
The function 'PhDrawFixUpA' gets the 24-Bit bitmap.


First One Code:
char * szPicData = (char*)malloc(4000000);
PhDrawFixUpA(szPicData);
BITMAPFILEHEADER bmpFileHeader;
memcpy(&bmpFileHeader,szPicData,sizeof(BITMAPFILEHEADER));
BITMAPINFOHEADER bmpInfoHeader;
memcpy(&bmpInfoHeader,szPicData+sizeof(BITMAPFILEHEADER),sizeof(BITMAPINFOHEADER));
BITMAPINFO bmpInfo;
memcpy(&bmpInfo,szPicData+sizeof(BITMAPFILEHEADER),sizeof(BITMAPINFO));
BITMAP bitmap;
bitmap.bmType = 0;
bitmap.bmWidth = bmpInfoHeader.biWidth;
bitmap.bmHeight = bmpInfoHeader.biHeight;
bitmap.bmWidthBytes = (bmpInfoHeader.biWidth*bmpInfoHeader.biBitCount/8 + 3)/4*4;
bitmap.bmPlanes = 1;
bitmap.bmBitsPixel = bmpInfoHeader.biBitCount;
bitmap.bmBits = szPicData+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFO);
static HBITMAP hBitmap = CreateBitmapIndirect(&bitmap);
SendDlgItemMessage(hDlg,IDP_DRAWPIC,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hBitmap);



The problem is I can't see anything in the 'Picture Control'.



Second One Code:
char * szPicData = (char*)malloc(4000000);
PhDrawFixUpA(szPicData);
BITMAPFILEHEADER bmpFileHeader;
memcpy(&bmpFileHeader,szPicData,sizeof(BITMAPFILEHEADER));
BITMAPINFOHEADER bmpInfoHeader;
memcpy(&bmpInfoHeader,szPicData+sizeof(BITMAPFILEHEADER),sizeof(BITMAPINFOHEADER));
BITMAPINFO bmpInfo;
memcpy(&bmpInfo,szPicData+sizeof(BITMAPFILEHEADER),sizeof(BITMAPINFO));
static HBITMAP hBitmap = CreateBitmap(bmpInfoHeader.biWidth, bmpInfoHeader.biHeight,1,
      bmpInfoHeader.biPlanes,szPicData+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFO));

SendDlgItemMessage(hDlg,IDP_DRAWPIC,STM_SETIMAGE,IMAGE_BITMAP,LPARAM)hBitmap);



The problem is I can see things in the 'Picture Control', but the image is not the intended one.
Remark:
I save the Picture Data 'szPicData' as a bitmap file into my disk,and I can see what I want to.
Posted
Updated 17-Mar-10 21:47pm
v2

1 solution

Try (szPicData + bmpFileHeader.bfOffBits) to access the bits :)
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900