VC + + MFC Save the zoom BMP picture without losing true

Source: Internet
Author: User

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 (&AMP;DC1, $, $); DC2. CreateCompatibleDC (NULL); DC2. SelectObject (&BMP); intmode = Setstretchbltmode (DC2, Coloroncolor);//set non-distortion scalingDC2. STRETCHBLT (0,0, $, $, &AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.