voidCsaveview::onfilesave () {BITMAP info;//Original pictureM_bitmap. Getbitmap (&info); CDC DC1; DC1. CreateCompatibleDC (NULL); DC1. SelectObject (&M_bitmap); DC1. MoveTo (0,0); DC1. LineTo (Info.bmwidth,info.bmheight); CDC DC2; CBitmap bmp;//scaled pictureBmp. CreateCompatibleBitmap (&DC1, $, $); DC2. CreateCompatibleDC (NULL); DC2. SelectObject (&BMP); intmode = Setstretchbltmode (DC2, Coloroncolor);//set non-distortion scalingDC2. STRETCHBLT (0,0, $, $, &DC1,0,0, info.bmwidth,info.bmheight,srccopy); Setstretchbltmode (DC2, mode); CFileDialog Dlg (false,"BMP", Null,ofn_hidereadonly | Ofn_overwriteprompt,null, This); if(IDOK = =dlg. DoModal ()) {CString Bmpfile=dlg. GetPathName (); CFile file (bmpfile,cfile::modecreate|cfile::modewrite); BITMAP Binfo; Bmp. Getbitmap (&binfo); //Calculate palette Size intPanelsize =0; if(binfo.bmbitspixel< -)//non-True Color{panelsize=int(Pow (Double)2, Binfo.bmbitspixel) *sizeof(Rgbquad)); } //Defining bitmap Informationbitmapinfo* Bmapinfo = (bitmapinfo*) LocalAlloc (LPTR,sizeof(Bitmapinfoheader) +panelsize); Bmapinfo->bmiheader.bibitcount =Binfo.bmbitspixel; Bmapinfo->bmiheader.biclrimportant =0; Bmapinfo->bmiheader.bicompression =0; Bmapinfo->bmiheader.biheight =Binfo.bmheight; Bmapinfo->bmiheader.biplanes =Binfo.bmplanes; Bmapinfo->bmiheader.bisize =sizeof(Bitmapinfo); Bmapinfo->bmiheader.bisizeimage = binfo.bmheight*binfo.bmwidthbytes; Bmapinfo->bmiheader.biwidth =Binfo.bmwidth; Bmapinfo->bmiheader.bixpelspermeter =0; Bmapinfo->bmiheader.biypelspermeter =0; //get the actual data of a bitmap Char* PData =New Char[bmapinfo->Bmiheader.bisizeimage]; intLen = GetDIBits (Dc2.m_hdc,bmp,0, binfo.bmheight,pdata,bmapinfo,dib_rgb_colors); Bitmapfileheader Bfileheader; Bfileheader.bftype=0x4d42; Bfileheader.bfreserved1=0; Bfileheader.bfreserved2=0; Bfileheader.bfsize=sizeof(Bitmapfileheader); Bfileheader.bfoffbits=sizeof(Bitmapfileheader) +sizeof(Bitmapinfoheader) +panelsize; //writing bitmap data to a fileFile. Write (&bfileheader,sizeof(Bitmapfileheader)); File. Write (&bmapinfo->bmiheader,sizeof(Bitmapinfoheader)); File. Write (Pdata,bmapinfo->bmiheader.bisizeimage+panelsize); File. Close (); Delete PData; LocalFree (Bmapinfo); } }
VC + + MFC Save the zoom BMP picture without losing true