The code below
cstrings filter;
The filter="all files (*. BMP, JPG, *. GIF, * tiff) | *. BMP. *.jpg. *.gif; *. Tiff | BMP (*. BMP) | *. BMP | JPG (*.jpg) | *. JPG | GIF (*. GIF) | *. GIF | tiff (*. Tiff) | *. Tiff | | ";
CFileDialog DLG (TRUE, NULL, NULL, OFN_HIDEREADONLY, filter, NULL);
//sure button DLG. DoModal () function display dialog
If (DLG) DoModal ()==IDOK)
{
//the open dialog box for image information
Cstrings BmpName=DLG. GetPathName ();//the file path name such as D: \ \ PIC ABC. BMP
Cstrings EntName=DLG. GetFileExt ();//get file extension
EntName. MakeLower ();//convert file extension to a lowercase characters
If (EntName.Com pare said (_T (BMP))==0)
{
//define variables stored image information
BITMAPINFO * pBmpInfo;//record image detail
BYTE * pBmpData;//image data
BITMAPFILEHEADER bmpHeader;//file header
BITMAPINFOHEADER bmpInfo;//information head
CFile bmpFile;//record open file
//to open the file read-only way read in all parts of BMP images BMP file header information data
if(! BmpFile. Open (BmpName, CFile: : modeRead | CFile: : typeBinary))
return;
If (bmpFile. Read (& amp; BmpHeader, sizeof (BITMAPFILEHEADER))!=sizeof (BITMAPFILEHEADER))
return;
If (bmpFile. Read (& amp; BmpInfo, sizeof (BITMAPINFOHEADER))!=sizeof (BITMAPINFOHEADER))
return;
PBmpInfo=(BITMAPINFO *) new char [sizeof (BITMAPINFOHEADER)];
//space for image data application
Memcpy (pBmpInfo, & amp; BmpInfo, sizeof (BITMAPINFOHEADER));//
DWORD dataBytes=bmpHeader. BfSize - bmpHeader. BfOffBits;
PBmpData=https://bbs.csdn.net/topics/(BYTE *) new char [dataBytes];
BmpFile. Read (pBmpData dataBytes);
BmpFile. Close ();
PBmpInfo - & gt; BmiHeader. BiBitCount=8;
//display images
The CWnd * pWnd=GetDlgItem (IDC_STATIC_PIC);//get the pictrue control window handle
CRect the rect.
PWnd - & gt; GetClientRect (& amp; The rect);//get the pictrue controls the rectangular area
The CDC * pDC=pWnd - & gt; GetDC ();//get the pictrue controls the DC
PDC - & gt; SetStretchBltMode (WHITEONBLACK);//COLORONCOLOR HALFTONE BLACKONWHITE WHITEONBLACK
StretchDIBits (pDC - & gt; GetSafeHdc (),
0,
0,
The rect. Width (),
The rect. Height (),
0,
0,
BmpInfo biWidth,
BmpInfo biHeight,
PBmpData,
PBmpInfo,
DIB_RGB_COLORS,
SRCCOPY
);
}
}
Find a lot of posts on the net, may and pBmpInfo SetStretchBltMode, DIB_RGB_COLORS, set about, but try for a long time still can't solve the problem... Moderator said can use CImage but there is no source file...
CodePudding user response:
Settings SetBKMode (TRANSPARENT) a try?CodePudding user response:
8-bit color and Dib bit depth below figure shows normal needs palette SelectPalettehttp://blog.csdn.net/sjiang2142/article/details/6445082
CodePudding user response: