




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
截图及保存显示相关void CZoomPartView:OnDraw(CDC* pDC)CZoomPartDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data here/声明判D断?是?否?load位?图?的?静2态?标志?static bool load;/按原-来大小?显?示?位?图?if (!load) BITMAP bm;load = !load;m_pBitmap-LoadBitmap(IDB_BITMAP1);m_pdcMem-CreateCompatibleDC(pDC);m_pdcMem-SelectObject(m_pBitmap);m_pBitmap-GetObject(sizeof(bm),&bm);m_sizeSource.cx = bm.bmWidth;m_sizeSource.cy = bm.bmHeight;m_sizeDest = m_sizeSource;pDC-StretchBlt(0,0,m_sizeSource.cx,m_sizeSource.cy,m_pdcMem,0,0,m_sizeSource.cx,m_sizeSource.cy,mana);else pDC-StretchBlt(0,0,m_sizeSource.cx,m_sizeSource.cy,m_pdcMem,0,0,m_sizeSource.cx,m_sizeSource.cy,mana);void CZoomPartView:OnMouseMove(UINT nFlags, CPoint point) /计?算?要a放?大的?局?部?矩?形?的?源图?像?位?置?和目?标位?置?CString cord;int dd; CRect srect,drect,mrect;srect.left = point.x - s;srect.top = point.y - s;srect.right = point.x + s;srect.bottom = point.y + s;drect.left = point.x - d;drect.top = point.y - d;drect.right = point.x + d;drect.bottom = point.y + d;mrect.left = oldx - d;mrect.top = oldy - d;mrect.right = oldx + d;mrect.bottom = oldy + d;dd = 2*d;CDC * pDC = GetDC();OnPrepareDC(pDC);/放?大图?像?if (recover)pDC-BitBlt(mrect.left,mrect.top,dd,dd,m_pdcMem,mrect.left,mrect.top,mana);pDC-StretchBlt(drect.left,drect.top,drect.Width(),drect.Height(),m_pdcMem,srect.left,srect.top,srect.Width(),srect.Height(),SRCCOPY);oldx = point.x; oldy = point.y;ReleaseDC(pDC);recover = true;CView:OnMouseMove(nFlags, point);void CZoomPartView:OnLButtonDown(UINT nFlags, CPoint point) /如?果?鼠标位?置?不?在位?图?上?,?则还1原-位?图?大小?显?示?CRect rc(0,0,m_sizeSource.cx,m_sizeSource.cy);if(!rc.PtInRect(point)Invalidate();else if (d 5)/如?果?放?大倍?数y大于5,?就继续?减?小?放?大倍?数y,?然?后进?行D放?大显?示?CDC * pDC = GetDC();pDC-StretchBlt(oldx - d,oldy - d,2*d,2*d,m_pdcMem,oldx - d,oldy - d,2*d,2*d,mana);d -= 10;ReleaseDC(pDC);CZoomPartView:OnMouseMove(nFlags, point); CView:OnLButtonDown(nFlags, point);void CZoomPartView:OnRButtonDown(UINT nFlags, CPoint point) /如?果?鼠标位?置?不?在位?图?上?,?则还1原-位?图?大小?显?示?CRect rc(0,0,m_sizeSource.cx,m_sizeSource.cy);if(!rc.PtInRect(point)Invalidate();else if (d 150)/如?果?放?大倍?数y小?于150,?就继续?增?加放?大倍?数y,?然?后进?行D放?大显?示? d += 10;CZoomPartView:OnMouseMove(nFlags, point); CView:OnRButtonDown(nFlags, point);/如?果?放?大倍?数y小?于150,?就继续?增?加放?大倍?数y,?然?后进?行D放?大显?示?void CCaptureDlg:SaveBmp()CDC dc;dc.CreateDC(DISPLAY,NULL,NULL,NULL);CBitmap bm;int Width=GetSystemMetrics(SM_CXSCREEN);int Height=GetSystemMetrics(SM_CYSCREEN);bm.CreateCompatibleBitmap(&dc,Width,Height);CDC tdc;tdc.CreateCompatibleDC(&dc);CBitmap*pOld=tdc.SelectObject(&bm);tdc.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY);tdc.SelectObject(pOld);BITMAP btm;bm.GetBitmap(&btm);DWORD size=btm.bmWidthBytes*btm.bmHeight;LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);/BITMAPINFOHEADER bih;bih.biBitCount=btm.bmBitsPixel;bih.biClrImportant=0;bih.biClrUsed=0;bih.biCompression=0;bih.biHeight=btm.bmHeight;bih.biPlanes=1;bih.biSize=sizeof(BITMAPINFOHEADER);bih.biSizeImage=size;bih.biWidth=btm.bmWidth;bih.biXPelsPerMeter=0;bih.biYPelsPerMeter=0;/GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);/bm.GetBitmapBits(size,lpData);/此?函数y在处|理5-5-5模式?的?16位?色?下?会出?现?颜?色?混乱/static int filecount=0;CString name;name.Format(pict%04d.bmp,filecount+);name=m_Path+name;BITMAPFILEHEADER bfh;bfh.bfReserved1=bfh.bfReserved2=0;bfh.bfType=(WORD)(M 8)|B);bfh.bfSize=54+size;bfh.bfOffBits=54;CFile bf;if(bf.Open(name,CFile:modeCreate|CFile:modeWrite)bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER);bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER);bf.WriteHuge(lpData,size);bf.Close();nCount+;GlobalFreePtr(lpData);if(nCount=1)m_Number.Format(%d picture captured.,nCount);elsem_Number.Format(%d pictures captured.,nCount);UpdateData(FALSE);For CBitmap objects we can use the GetBitmap() function to determine the height and width of the bitmap. / The variable bitmap is a CBitmap objectBITMAP bm;bitmap.GetBitmap( &bm );bmWidth = bm.bmWidth;bmHeight = bm.bmHeight;If you have a HBITMAP, you can attach it to a CBitmap object and use the method shown above or you can use / The variable hBmp is a HBITMAPBITMAP bm;:GetObject( hBmp, sizeof( bm ), &bm );bmWidth = bm.bmWidth;bmHeight = bm.bmHeight;For images in a BMP file, you can use something like CFile file;/ sBMPFileName is the BMP filenameif( !file.Open( sBMPFileName, CFile:modeRead) )return ;BITMAPFILEHEADER bmfHeader;/ Read file headerif (file.Read(LPSTR)&bmfHeader, sizeof(bmfHeader) != sizeof(bmfHeader)return ;/ File type should be BMif (bmfHeader.bfType != (WORD) (M 8) | B)return ;BITMAPINFOHEADER bmiHeader;if (file.Read(LPSTR)&bmiHeader, sizeof(bmiHeader) != sizeof(bmiHeader)return ;int bmWidth = bmiHeader.biWidth;int bmHeight = bmiHeader.biHeight;Within your program, you may have three different forms of a bitmap, a device-independent bitmap (DIB), a device-dependent bitmap (DDB) and a DIB section. The DIB is essentially a representation of bitmap in a manner that is independent of any device. It contains the information to enable it to be rendered on any device. There are different versions of DIBs, the most common being version 3. The specification for version 4 has also been released but this format is not yet as prevalent. There are two drawbacks to using a DIB; there are fewer functions that handle a DIB and it takes longer to render a DIB. The device-dependent bitmap is specific to a device and it is very unlikely that a DDB for one device can be rendered on another. One such situation is when you want to render an image from the screen to a printer. In this case you would have to change the DDB to a DIB before you try to render it onto the printer. Most of the GDI functions take a DDB as an argument instead on a DIB. The DIB section is somewhat new and designed to alleviate some of the problems with a DIB. You can use a DIB section wherever you use a DDB and yet have access to the bitmap bits and the color information. All this preamble was basically to say that you need one function to render a DIB and another to render a DDB or a DIB section. Function 1: DrawDIBThe DrawDIB() function uses the function SetDIBitsToDevice() for to render the image. When using this function, you should be aware that the BMP file is arranged such that the first scan line (first row of pixels) is the bottom most scan line. You could actually have the top most scan line be the first if the height of the bitmap is specified as a negative value but this is rarely used. So if you want only the top half of the bitmap drawn then the nStartScan value should be half of nNumScans. You can also use the StretchDIBits() to render the bitmap data onto a device. The StretchDIBits() function is more versatile in that it allows the bitmap to be streched or compressed and it can use various raster operations to generate the image. The StretchDIBits() function can also be used to mirror the image. One of the argument to the DrawDIB() function is the palette that should be used when rendering the bitmap. This information can be derived from the DIB itself but using a predefined palette can help speed things up slightly. / DrawDIB- Draws a DIB onto a device/ pDC- Pointer to a device context/ hDIB- Handle of the device-independent bitmap/ pPal- Pointer to a palette associated with the DIB/ xDest- x-coordinate of the upper-left corner of the destination rect/ yDest- y-coordinate of the upper-left corner of the destination rectvoid DrawDIB( CDC* pDC, HGLOBAL hDIB, CPalette *pPal, int xDest, int yDest )LPVOID lpDIBBits; / Pointer to DIB bitsBOOL bSuccess=FALSE; / Success/fail flagBITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ;int nColors = bmInfo.bmiHeader.biClrUsed ? bmInfo.bmiHeader.biClrUsed : 1 8 )lpDIBBits = (LPVOID)(LPDWORD)(bmInfo.bmiColors + bmInfo.bmiHeader.biClrUsed) + (bmInfo.bmiHeader.biCompression = BI_BITFIELDS) ? 3 : 0);elselpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);/ Select and realize the palette if one supplied and if device supports itif( pPal & (pDC-GetDeviceCaps(RASTERCAPS) & RC_PALETTE) )pDC-SelectPalette(pPal, FALSE);pDC-RealizePalette();:SetDIBitsToDevice(pDC-m_hDC, / hDCxDest, / DestXyDest, / DestYbmInfo.bmiHeader.biWidth, / nDestWidthbmInfo.bmiHeader.biHeight, / nDestHeight0, / SrcX0, / SrcY0, / nStartScanbmInfo.bmiHeader.biHeight, / nNumScanslpDIBBits, / lpBits(LPBITMAPINFO)hDIB, / lpBitsInfoDIB_RGB_COLORS); / wUsageFunction 2: DrawBitmapThe DrawBitmap() function can be used with both a DDB and a DIB section. This function does take into account that the destination device context might have a map mode other than MM_TEXT. This might not work always or the effect may not be what you want. / DrawBitmap- Draws a bitmap (DDB & DIB section) onto a device/ pDC- Pointer to a device context/ hBitmap- Handle of the bitmap/ hPal- Handle of a logical palette associated with the bitmap/ xDest- x-coordinate of the upper-left corner of the destination rect/ yDest- y-coordinate of the upper-left corner of the destination rectvoid DrawBitmap( CDC *pDC, HBITMAP hBitmap, HPALETTE hPal, int xDest, int yDest )/ Get logical coordinatesBITMAP bm;:GetObject( hBitmap, sizeof( bm ), &bm );CPoint size( bm.bmWidth, bm.bmHeight );pDC-DPtoLP(&size);CPoint org(0,0);pDC-DPtoLP(&org);/ Create a memory DC compatible with the destination DCCDC memDC;memDC.CreateCompatibleDC( pDC );memDC.SetMapMode( pDC-GetMapMode() );/memDC.SelectObject( &bitmap );HBITMAP hBmOld = (HBITMAP):SelectObject( memDC.m_hDC, hBitmap );/ Select and realize the paletteif( hPal & pDC-GetDeviceCaps(RASTERCAPS) & RC_PALETTE)SelectPalette( pDC-GetSafeHdc(), hPal, FALSE );pDC-RealizePalette();pDC-BitBlt(xDest, yDest, size.x, size.y, &memDC, org.x, org.y, SRCCOPY);:SelectObject( memDC.m_hDC, hBmOld );Function 3: DrawDIBSectionAlthough we can use the DrawBitmap() function to draw a DIB section as well, this functions takes the color information of the bitmap into consideration and will create and use an appropriate palette when needed. Note that since this function may create a palette in each call, it might be better, for performance reasons, to create an appropriate palette from the DIB section and use the DrawBitmap() function instead. The DrawDIBSection() is handy if DIB sections color information is modified before displaying it. / DrawDIBSection- Draws a DIB section onto a device/ hDC- Handle to a device context/ hBitmap- Handle of the DIB Section/ xDest- x-coordinate of the upper-left corner of the destination rect/ yDest- y-coordinate of the upper-left corner of the destination rectvoid DrawDIBSection( HDC hDC, HBITMAP hBitmap, int xDest, int yDest )HPALETTE hPal;HDC hDCMem = :CreateCompatibleDC( hDC );/ Create a logical palette for the bitmapDIBSECTION ds;BITMAPINFOHEADER &bmInfo = ds.dsBmih;if( :GetObject(hBitmap, sizeof(ds), &ds ) = 0 )return;/ Not a DIB SectionHGDIOBJ hBmpOld = :SelectObject(hDCMem, hBitmap);int nColors = bmInfo.biClrUsed ? bmInfo.biClrUsed : 1 256. if( nColors 256 )hPal = :CreateHalftonePalette(hDC);else/ Create the paletteRGBQUAD *pRGB = new RGBQUADnColors;:GetDIBColorTable( hDCMem, 0, nColors, pRGB );UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);LOGPALETTE *pLP = (LOGPALETTE *) new BYTEnSize;pLP-palVersion = 0x300;pLP-palNumEntries = nColors;for( int i=0; i palPalEntryi.peRed = pRGBi.rgbRed;pLP-palPalEntryi.peGreen = pRGBi.rgbGreen;pLP-palPalEntryi.peBlue = pRGBi.rgbBlue;pLP-palPalEntryi.peFlags = 0;hPal = :CreatePalette( pLP );delete pLP;delete pRGB;HPALETTE hPalOld = :SelectPalette(hDC,hPal,FALSE);:RealizePalette(hDC);BitBlt(hDC,xDest,yDest,bmInfo.biWidth,bmInfo.biHeight,hDCMem,0,0,SRCCOPY);:SelectPalette(hDC,hPalOld,FALSE);/ delete GDI objects:DeleteObject(hPal);elseBitBlt(hDC,xDest,yDes
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 相遇问题试讲题目及答案
- 2025年九年级数学秋季开学摸底考(江苏专用)含答案
- 2025年G1工业锅炉司炉证考试题库及答案
- 2025年5月计算机文化基础模拟考试题与答案
- 2025物业服务合同管理规范范本
- 2025年4月肿瘤专科练习题库(含参考答案)
- 2025年4月基础医学概论模拟习题(含参考答案)
- 2025-2026学年七年级语文上册第五单元检测培优卷( 含答案)
- 2025年沪教版八年级英语上册预习Unit1【含答案解析】
- 营销培训知识大全课件
- 甲状腺手术甲状旁腺保护
- GB/T 2820.7-2024往复式内燃机驱动的交流发电机组第7部分:用于技术条件和设计的技术说明
- 施工项目部会议管理制度
- 欢迎一年级新生入学课件
- 译林版七年级上册英语阅读理解专项练习题100篇含答案
- 夫妻婚内财产协议书(2024版)
- (正式版)JTT 1495-2024 公路水运危险性较大工程安全专项施工方案审查规程
- 20G520-1-2钢吊车梁(6m-9m)2020年合订本
- 19R505-19G540室外管道钢结构架空综合管廊敷设
- 机械制造基础说课市公开课一等奖省赛课微课金奖课件
- 会员评家民主测评表、评主席测评表
评论
0/150
提交评论