首页 随笔 乐走天涯 程序资料 评论中心 Tag 论坛 其他资源 搜索 联系我 关于 RSS

镜像位图


日期: 2002-01-27 14:00 | 联系我 | 关注我: Telegram, Twitter

本程序介绍如何横向或纵向镜像位图,效果图如下。

函数一:DrawInvertedBitmap

DrawInvertedBitmap()在指定位置绘制位图的镜像图,它使用 StretchBlt()进行镜像。当源和目标的宽度的相反时,图像进行横向镜像;反之,进行纵向镜像。

// DrawInvertedBitmap - Draws the bitmap after inverting it // hBimtap - Bitmap handle // hPal - Palette to use when drawing the bitmap // bLateral - Flag to indicate whether to invert laterally or vertically // xDest - X coordinate of top left corner to draw at // yDest - Y coordinate of top left corner to draw at void DrawInvertedBitmap( CDC *pDC, HBITMAP hBitmap, HPALETTE hPal, BOOL bLateral, int xDest, int yDest ) { // Create a memory DC compatible with the destination DC CDC memDC; memDC.CreateCompatibleDC( pDC ); // Get logical coordinates BITMAP bm; ::GetObject( hBitmap, sizeof( bm ), &bm ); //memDC.SelectObject( &bitmap ); HBITMAP hBmOld = (HBITMAP)::SelectObject( memDC.m_hDC, hBitmap ); // Select and realize the palette if( hPal && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { SelectPalette( pDC->GetSafeHdc(), hPal, FALSE ); pDC->RealizePalette(); } if( bLateral ) pDC->StretchBlt( xDest, yDest, bm.bmWidth, bm.bmHeight, &memDC, bm.bmWidth-1, 0, -bm.bmWidth, bm.bmHeight, SRCCOPY ); else pDC->StretchBlt( xDest, yDest, bm.bmWidth, bm.bmHeight, &memDC, 0, bm.bmHeight-1, bm.bmWidth, -bm.bmHeight, SRCCOPY ); // Restore the old bitmap ::SelectObject( memDC.m_hDC, hBmOld ); }函数二:GetInvertedBitmap

GetInvertedBitmap()函数创建新的位图来存储镜像位图,该函数使用 StretchBlt()进行镜像。在这种情况下,目标设备环境是另外一个内存设备环境,这样,图像就被显示在位图上。

// GetInvertedBitmap - Creates a new bitmap with the inverted image // Returns - Handle to a new bitmap with inverted image // hBitmap - Bitmap to invert // bLateral - Flag to indicate whether to invert laterally or vertically HBITMAP GetInvertedBitmap( HBITMAP hBitmap, BOOL bLateral ) { // Create a memory DC compatible with the display CDC sourceDC, destDC; sourceDC.CreateCompatibleDC( NULL ); destDC.CreateCompatibleDC( NULL ); // Get logical coordinates BITMAP bm; ::GetObject( hBitmap, sizeof( bm ), &bm ); // Create a bitmap to hold the result HBITMAP hbmResult = ::CreateCompatibleBitmap(CClientDC(NULL), bm.bmWidth, bm.bmHeight); // Select bitmaps into the DCs HBITMAP hbmOldSource = (HBITMAP)::SelectObject( sourceDC.m_hDC, hBitmap ); HBITMAP hbmOldDest = (HBITMAP)::SelectObject( destDC.m_hDC, hbmResult ); if( bLateral ) destDC.StretchBlt( 0, 0, bm.bmWidth, bm.bmHeight, &sourceDC, bm.bmWidth-1, 0, -bm.bmWidth, bm.bmHeight, SRCCOPY ); else destDC.StretchBlt( 0, 0, bm.bmWidth, bm.bmHeight, &sourceDC, 0, bm.bmHeight-1, bm.bmWidth, -bm.bmHeight, SRCCOPY ); // Reselect the old bitmaps ::SelectObject( sourceDC.m_hDC, hbmOldSource ); ::SelectObject( destDC.m_hDC, hbmOldDest ); return hbmResult; }


 文章评论
目前没有任何评论.

↓ 快抢占第1楼,发表你的评论和意见 ↓

发表你的评论
如果你想针对此文发表评论, 请填写下列表单:
姓名: * 必填 (Twitter 用户可输入以 @ 开头的用户名, Steemit 用户可输入 @@ 开头的用户名)
E-mail: 可选 (不会被公开。如果我回复了你的评论,你将会收到邮件通知)
反垃圾广告: 为了防止广告机器人自动发贴, 请计算下列表达式的值:
9 x 3 + 5 = * 必填
评论内容:
* 必填
你可以使用下列标签修饰文字:
[b] 文字 [/b]: 加粗文字
[quote] 文字 [/quote]: 引用文字

 
首页 随笔 乐走天涯 猎户星 Google Earth 程序资料 程序生活 评论 Tag 论坛 资源 搜索 联系 关于 隐私声明 版权声明 订阅邮件

程序员小辉 建站于 1997 ◇ 做一名最好的开发者是我不变的理想。
Copyright © XiaoHui.com; 保留所有权利。