- 浏览: 5099549 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
silence19841230:
先拿走看看
SpringBoot2.0开发WebSocket应用完整示例 -
wallimn:
masuweng 写道发下源码下载地址吧!三个相关文件打了个包 ...
SpringBoot2.0开发WebSocket应用完整示例 -
masuweng:
发下源码下载地址吧!
SpringBoot2.0开发WebSocket应用完整示例 -
masuweng:
SpringBoot2.0开发WebSocket应用完整示例 -
wallimn:
水淼火 写道你好,我使用以后,图标不显示,应该怎么引用呢,谢谢 ...
前端框架iviewui使用示例之菜单+多Tab页布局
转自:http://hi.baidu.com/sweetpigss/blog/item/0496efdc5d1967d08c10297e.html
如果你的应用程序仅工作在Windows NT下,那么你可以通过API函数旋转你的位图。
你或者使用world transformation和BitBlt()或者使用PlgBlt()旋转位图。一个
使用第一种方法的函数显示在下面。
如果你的目标是多平台的,那么你的任务变得非常困难。你只能通过旋转源位图中
每个象素或者直接操作DIB字节得到旋转位图。第一种方法通过每个点的处理是非
常慢的,第二种方法是很复杂的,但它有足够快的速度。注:下面的所有函数旋转
后产生新的位图,如果你需要直接绘制位图,请自已修改函数。 其中函数1仅工作
在NT环境下,它是最简单也是最快的,可惜它不支持Windows95。
所有的函数所接受的角度单位是弧度,如果是角度单位是度请用下面的公式转换。
radian = (2*pi *degree)/360
旋转步骤:
创建一对与设备兼容的显示设备。一个用于源位图,一个用于旋转后的目标位图。
预计算正弦和余弦函数值,这样可以避免重复计算。
用下面的公式计算旋转图像后的矩形
newx = x.cos(angle) + y.sin(angle)
newy = y.cos(angle) - x.sin(angle)
旋转后的位图将不能占用整个新位图,我们将用背景色填充它。
点阵转换公式
newx = x * eM11 + y * eM21 + eDx
newy = x * eM12 + y * eM22 + eDy
其中eM11和eM22是角度的余弦值,eM21是角度的正弦,eM12是eM21的负值。 eDx & eDy
目的是旋转后的位图在新的位图不被剪切。
函数一:适用于NT
函数二: GetRotatedBitmap()使用 GetPixel & SetPixel
函数三: GetRotatedBitmap()使用DIB
如果你的应用程序仅工作在Windows NT下,那么你可以通过API函数旋转你的位图。
你或者使用world transformation和BitBlt()或者使用PlgBlt()旋转位图。一个
使用第一种方法的函数显示在下面。
如果你的目标是多平台的,那么你的任务变得非常困难。你只能通过旋转源位图中
每个象素或者直接操作DIB字节得到旋转位图。第一种方法通过每个点的处理是非
常慢的,第二种方法是很复杂的,但它有足够快的速度。注:下面的所有函数旋转
后产生新的位图,如果你需要直接绘制位图,请自已修改函数。 其中函数1仅工作
在NT环境下,它是最简单也是最快的,可惜它不支持Windows95。
所有的函数所接受的角度单位是弧度,如果是角度单位是度请用下面的公式转换。
radian = (2*pi *degree)/360
旋转步骤:
创建一对与设备兼容的显示设备。一个用于源位图,一个用于旋转后的目标位图。
预计算正弦和余弦函数值,这样可以避免重复计算。
用下面的公式计算旋转图像后的矩形
newx = x.cos(angle) + y.sin(angle)
newy = y.cos(angle) - x.sin(angle)
旋转后的位图将不能占用整个新位图,我们将用背景色填充它。
点阵转换公式
newx = x * eM11 + y * eM21 + eDx
newy = x * eM12 + y * eM22 + eDy
其中eM11和eM22是角度的余弦值,eM21是角度的正弦,eM12是eM21的负值。 eDx & eDy
目的是旋转后的位图在新的位图不被剪切。
函数一:适用于NT
// GetRotatedBitmapNT - Create a new bitmap with rotated image // Returns - Returns new bitmap with rotated image // hBitmap - Bitmap to rotate // radians - Angle of rotation in radians // clrBack - Color of pixels in the resulting bitmap that do // not get covered by source pixels HBITMAP GetRotatedBitmapNT( HBITMAP hBitmap, float radians, COLORREF clrBack ) { // 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 ); float cosine = (float)cos(radians); float sine = (float)sin(radians); // Compute dimensions of the resulting bitmap // First get the coordinates of the 3 corners other than origin int x1 = (int)(bm.bmHeight * sine); int y1 = (int)(bm.bmHeight * cosine); int x2 = (int)(bm.bmWidth * cosine + bm.bmHeight * sine); int y2 = (int)(bm.bmHeight * cosine - bm.bmWidth * sine); int x3 = (int)(bm.bmWidth * cosine); int y3 = (int)(-bm.bmWidth * sine); int minx = min(0,min(x1, min(x2,x3))); int miny = min(0,min(y1, min(y2,y3))); int maxx = max(0,max(x1, max(x2,x3))); int maxy = max(0,max(y1, max(y2,y3))); int w = maxx - minx; int h = maxy - miny; // Create a bitmap to hold the result HBITMAP hbmResult = ::CreateCompatibleBitmap(CClientDC(NULL), w, h); HBITMAP hbmOldSource = (HBITMAP)::SelectObject( sourceDC.m_hDC, hBitmap ); HBITMAP hbmOldDest = (HBITMAP)::SelectObject( destDC.m_hDC, hbmResult ); // Draw the background color before we change mapping mode HBRUSH hbrBack = CreateSolidBrush( clrBack ); HBRUSH hbrOld = (HBRUSH)::SelectObject( destDC.m_hDC, hbrBack ); destDC.PatBlt( 0, 0, w, h, PATCOPY ); ::DeleteObject( ::SelectObject( destDC.m_hDC, hbrOld ) ); // We will use world transform to rotate the bitmap SetGraphicsMode(destDC.m_hDC, GM_ADVANCED); XFORM xform; xform.eM11 = cosine; xform.eM12 = -sine; xform.eM21 = sine; xform.eM22 = cosine; xform.eDx = (float)-minx; xform.eDy = (float)-miny; SetWorldTransform( destDC.m_hDC, &xform ); // Now do the actual rotating - a pixel at a time destDC.BitBlt(0,0,bm.bmWidth, bm.bmHeight, &sourceDC, 0, 0, SRCCOPY ); // Restore DCs ::SelectObject( sourceDC.m_hDC, hbmOldSource ); ::SelectObject( destDC.m_hDC, hbmOldDest ); return hbmResult; }
函数二: GetRotatedBitmap()使用 GetPixel & SetPixel
// GetRotatedBitmap - Create a new bitmap with rotated image // Returns - Returns new bitmap with rotated image // hBitmap - Bitmap to rotate // radians - Angle of rotation in radians // clrBack - Color of pixels in the resulting bitmap that do // not get covered by source pixels // Note - If the bitmap uses colors not in the system palette // then the result is unexpected. You can fix this by // adding an argument for the logical palette. HBITMAP GetRotatedBitmap( HBITMAP hBitmap, float radians, COLORREF clrBack ) { // 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 ); float cosine = (float)cos(radians); float sine = (float)sin(radians); // Compute dimensions of the resulting bitmap // First get the coordinates of the 3 corners other than origin int x1 = (int)(-bm.bmHeight * sine); int y1 = (int)(bm.bmHeight * cosine); int x2 = (int)(bm.bmWidth * cosine - bm.bmHeight * sine); int y2 = (int)(bm.bmHeight * cosine + bm.bmWidth * sine); int x3 = (int)(bm.bmWidth * cosine); int y3 = (int)(bm.bmWidth * sine); int minx = min(0,min(x1, min(x2,x3))); int miny = min(0,min(y1, min(y2,y3))); int maxx = max(x1, max(x2,x3)); int maxy = max(y1, max(y2,y3)); int w = maxx - minx; int h = maxy - miny; // Create a bitmap to hold the result HBITMAP hbmResult = ::CreateCompatibleBitmap(CClientDC(NULL), w, h); HBITMAP hbmOldSource = (HBITMAP)::SelectObject( sourceDC.m_hDC, hBitmap ); HBITMAP hbmOldDest = (HBITMAP)::SelectObject( destDC.m_hDC, hbmResult ); // Draw the background color before we change mapping mode HBRUSH hbrBack = CreateSolidBrush( clrBack ); HBRUSH hbrOld = (HBRUSH)::SelectObject( destDC.m_hDC, hbrBack ); destDC.PatBlt( 0, 0, w, h, PATCOPY ); ::DeleteObject( ::SelectObject( destDC.m_hDC, hbrOld ) ); // Set mapping mode so that +ve y axis is upwords sourceDC.SetMapMode(MM_ISOTROPIC); sourceDC.SetWindowExt(1,1); sourceDC.SetViewportExt(1,-1); sourceDC.SetViewportOrg(0, bm.bmHeight-1); destDC.SetMapMode(MM_ISOTROPIC); destDC.SetWindowExt(1,1); destDC.SetViewportExt(1,-1); destDC.SetWindowOrg(minx, maxy); // Now do the actual rotating - a pixel at a time // Computing the destination point for each source point // will leave a few pixels that do not get covered // So we use a reverse transform - e.i. compute the source point // for each destination point for( int y = miny; y < maxy; y++ ) { for( int x = minx; x < maxx; x++ ) { int sourcex = (int)(x*cosine + y*sine); int sourcey = (int)(y*cosine - x*sine); if( sourcex >= 0 && sourcex < bm.bmWidth && sourcey >= 0 && sourcey < bm.bmHeight ) destDC.SetPixel(x,y,sourceDC.GetPixel(sourcex,sourcey)); } } // Restore DCs ::SelectObject( sourceDC.m_hDC, hbmOldSource ); ::SelectObject( destDC.m_hDC, hbmOldDest ); return hbmResult; }
函数三: GetRotatedBitmap()使用DIB
// GetRotatedBitmap - Create a new bitmap with rotated image // Returns - Returns new bitmap with rotated image // hDIB - Device-independent bitmap to rotate // radians - Angle of rotation in radians // clrBack - Color of pixels in the resulting bitmap that do // not get covered by source pixels HANDLE GetRotatedBitmap( HANDLE hDIB, float radians, COLORREF clrBack) { // Get source bitmap info BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ; int bpp = bmInfo.bmiHeader.biBitCount; // Bits per pixel int nColors = bmInfo.bmiHeader.biClrUsed ? bmInfo.bmiHeader.biClrUsed : 1 << bpp; int nWidth = bmInfo.bmiHeader.biWidth; int nHeight = bmInfo.bmiHeader.biHeight; int nRowBytes = ((((nWidth * bpp) + 31) & ~31) / 8); // Make sure height is positive and biCompression is BI_RGB or BI_BITFIELDS DWORD &compression = bmInfo.bmiHeader.biCompression; if( nHeight < 0 || (compression!=BI_RGB && compression!=BI_BITFIELDS)) return NULL; LPVOID lpDIBBits; if( bmInfo.bmiHeader.biBitCount > 8 ) lpDIBBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors + bmInfo.bmiHeader.biClrUsed) + ((compression == BI_BITFIELDS) ? 3 : 0)); else lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors); // Compute the cosine and sine only once float cosine = (float)cos(radians); float sine = (float)sin(radians); // Compute dimensions of the resulting bitmap // First get the coordinates of the 3 corners other than origin int x1 = (int)(-nHeight * sine); int y1 = (int)(nHeight * cosine); int x2 = (int)(nWidth * cosine - nHeight * sine); int y2 = (int)(nHeight * cosine + nWidth * sine); int x3 = (int)(nWidth * cosine); int y3 = (int)(nWidth * sine); int minx = min(0,min(x1, min(x2,x3))); int miny = min(0,min(y1, min(y2,y3))); int maxx = max(x1, max(x2,x3)); int maxy = max(y1, max(y2,y3)); int w = maxx - minx; int h = maxy - miny; // Create a DIB to hold the result int nResultRowBytes = ((((w * bpp) + 31) & ~31) / 8); long len = nResultRowBytes * h; int nHeaderSize = ((LPBYTE)lpDIBBits-(LPBYTE)hDIB) ; HANDLE hDIBResult = GlobalAlloc(GMEM_FIXED,len+nHeaderSize); // Initialize the header information memcpy( (void*)hDIBResult, (void*)hDIB, nHeaderSize); BITMAPINFO &bmInfoResult = *(LPBITMAPINFO)hDIBResult ; bmInfoResult.bmiHeader.biWidth = w; bmInfoResult.bmiHeader.biHeight = h; bmInfoResult.bmiHeader.biSizeImage = len; LPVOID lpDIBBitsResult = (LPVOID)((LPBYTE)hDIBResult + nHeaderSize); // Get the back color value (index) ZeroMemory( lpDIBBitsResult, len ); DWORD dwBackColor; switch(bpp) { case 1: //Monochrome if( clrBack == RGB(255,255,255) ) memset( lpDIBBitsResult, 0xff, len ); break; case 4: case 8: //Search the color table int i; for(i = 0; i < nColors; i++ ) { if( bmInfo.bmiColors[i].rgbBlue == GetBValue(clrBack) && bmInfo.bmiColors[i].rgbGreen == GetGValue(clrBack) && bmInfo.bmiColors[i].rgbRed == GetRValue(clrBack) ) { if(bpp==4) i = i | i<<4; memset( lpDIBBitsResult, i, len ); break; } } // If not match found the color remains black break; case 16: // Windows95 supports 5 bits each for all colors or 5 bits for red & blue // and 6 bits for green - Check the color mask for RGB555 or RGB565 if( *((DWORD*)bmInfo.bmiColors) == 0x7c00 ) { // Bitmap is RGB555 dwBackColor = ((GetRValue(clrBack)>>3) << 10) + ((GetRValue(clrBack)>>3) << 5) + (GetBValue(clrBack)>>3) ; } else { // Bitmap is RGB565 dwBackColor = ((GetRValue(clrBack)>>3) << 11) + ((GetRValue(clrBack)>>2) << 5) + (GetBValue(clrBack)>>3) ; } break; case 24: case 32: dwBackColor = (((DWORD)GetRValue(clrBack)) << 16) | (((DWORD)GetGValue(clrBack)) << 8) | (((DWORD)GetBValue(clrBack))); break; } // Now do the actual rotating - a pixel at a time // Computing the destination point for each source point // will leave a few pixels that do not get covered // So we use a reverse transform - e.i. compute the source point // for each destination point for( int y = 0; y < h; y++ ) { for( int x = 0; x < w; x++ ) { int sourcex = (int)((x+minx)*cosine + (y+miny)*sine); int sourcey = (int)((y+miny)*cosine - (x+minx)*sine); if( sourcex >= 0 && sourcex < nWidth && sourcey >= 0 && sourcey < nHeight ) { // Set the destination pixel switch(bpp) { BYTE mask; case 1: //Monochrome mask = *((LPBYTE)lpDIBBits + nRowBytes*sourcey + sourcex/8) & (0x80 >> sourcex%8); //Adjust mask for destination bitmap mask = mask ? (0x80 >> x%8) : 0; *((LPBYTE)lpDIBBitsResult + nResultRowBytes*(y) + (x/8)) &= ~(0x80 >> x%8); *((LPBYTE)lpDIBBitsResult + nResultRowBytes*(y) + (x/8)) |= mask; break; case 4: mask = *((LPBYTE)lpDIBBits + nRowBytes*sourcey + sourcex/2) & ((sourcex&1) ? 0x0f : 0xf0); //Adjust mask for destination bitmap if( (sourcex&1) != (x&1) ) mask = (mask&0xf0) ? (mask>>4) : (mask<<4); *((LPBYTE)lpDIBBitsResult + nResultRowBytes*(y) + (x/2)) &= ~((x&1) ? 0x0f : 0xf0); *((LPBYTE)lpDIBBitsResult + nResultRowBytes*(y) + (x/2)) |= mask; break; case 8: BYTE pixel ; pixel = *((LPBYTE)lpDIBBits + nRowBytes*sourcey + sourcex); *((LPBYTE)lpDIBBitsResult + nResultRowBytes*(y) + (x)) = pixel; break; case 16: DWORD dwPixel; dwPixel = *((LPWORD)((LPBYTE)lpDIBBits + nRowBytes*sourcey + sourcex*2)); *((LPWORD)((LPBYTE)lpDIBBitsResult + nResultRowBytes*y + x*2)) = (WORD)dwPixel; break; case 24: dwPixel = *((LPDWORD)((LPBYTE)lpDIBBits + nRowBytes*sourcey + sourcex*3)) & 0xffffff; *((LPDWORD)((LPBYTE)lpDIBBitsResult + nResultRowBytes*y + x*3)) |= dwPixel; break; case 32: dwPixel = *((LPDWORD)((LPBYTE)lpDIBBits + nRowBytes*sourcey + sourcex*4)); *((LPDWORD)((LPBYTE)lpDIBBitsResult + nResultRowBytes*y + x*4)) = dwPixel; } } else { // Draw the background "color." tppabs="http://www.codeguru.com/bitmap/color." The background color // has already been drawn for 8 bits per pixel and less switch(bpp) { case 16: *((LPWORD)((LPBYTE)lpDIBBitsResult + nResultRowBytes*y + x*2)) = (WORD)dwBackColor; break; case 24: *((LPDWORD)((LPBYTE)lpDIBBitsResult + nResultRowBytes*y + x*3)) |= dwBackColor; break; case 32: *((LPDWORD)((LPBYTE)lpDIBBitsResult + nResultRowBytes*y + x*4)) = dwBackColor; break; } } } } return hDIBResult; }
发表评论
-
Delphi中编程实现TWebBrowser查找及上一个、下一个功能
2016-08-18 13:58 1315代码比较简单,全部内容如下: //1:向下搜索;-1:向上 ... -
OLEDB的Excel的IMEX和HDR是什么意思
2013-11-23 21:15 2084转自:http://blog.csdn.net/baple/a ... -
c#获取应用程序目录
2013-10-23 22:35 1704string str1 =Process.GetCurrent ... -
Visual C# 方案 -> 文本操作快捷键
2013-10-07 22:34 2010转自:http://technet.microsoft.com ... -
Visual Studio 2005快捷键大全
2013-10-07 22:29 1603转自:http://www.cnblogs.com/mekon ... -
C#正则表达式测试小工具
2013-10-04 18:51 4747C#的正则表达式使用比较方便,但复杂的正则表达式还是需要测 ... -
C#正则表达式语法规则详解
2013-10-04 17:26 3955正则表达式通常包含字 ... -
C# WINFORM 捕获全局异常
2013-10-01 11:56 2994using System; using System.Coll ... -
Visual C# 中XML注释的使用(含注释在开发时显示换行)
2013-10-01 11:54 2415在C#智能注释时,常常希望它能在开发时显示为换行,使得提示更加 ... -
DevExpress汉化(WinForm)
2013-09-19 17:27 8179/* *隔壁老王原创,2013-09-21,转载请保留本人信息 ... -
VC中的CImage类
2011-04-17 22:19 8863今天查找如何实现 ... -
VC多线程编程(转)
2010-12-22 21:11 3142原文地址:http://www.cnblo ... -
Manifest的问题
2010-05-11 10:08 2274原始连接:http://www.zming ... -
Asp.Net中Word,Excel等office com组件操作权限的问题
2010-05-06 13:57 10132近日在打开原来写的一 ... -
如何注销windows server2003 服务器中的远程连接
2009-12-14 01:29 3773碰到超过远程连接数而无法连接服务器,可以采用如下方法解决 ... -
访问WebBrowser控件中的HTML源码
2009-12-11 22:13 4065为了实现在自己的程序中显示HTML文档,我们一般采用IE(In ... -
Makefile详解(3/3)
2009-12-01 12:32 1514一、函数库文件的成员 一个函数库文件由多个文件组成。你可以以 ... -
Makefile详解(2/3)
2009-12-01 12:29 2187八、目标变量 前面我们所讲的在Makefile中定义的变量都 ... -
Makefile详解(1/3)
2009-12-01 12:27 2115原文地址:http://blog.csdn ... -
OLE DB 的概念
2009-11-20 22:41 2059简单地说,OLE DB 是 ...
相关推荐
在vc++中实现任意角度旋转位图、缩放图片和移动图片
对真彩色bmp图片旋转90度并保存,VC实现
VC程序, 通过运算公式,将图像旋转一定角度,可实现图像的旋转功能,并最后保存出图片来
VC6环境下的高质量图片旋转例程,包含所有工程文件
基于VC++语言,VS平台开发,应用GDI+库,双缓冲,实现图片旋转,屏幕不闪烁。代码量不大,简单易学。
VC BMP位图图像旋转实例,本程序只支持256色的图片旋转实例,真彩色位图暂不支持。
3D图片浏览器 vc OpenGL 源码 旋转
VC生成的DLL实现图片360旋转经典代码,很特别的一个例子推荐
VB通过调用VC生成的DLL实现图片360旋转 VB通过调用VC生成的DLL实现图片360旋转
void CCube1View::cube_def( ) { int i,j; CDC *pDC=GetDC(); CPen pen; pen.CreatePen(PS_SOLID,1,RGB(255,255,255)); CPen *poldpen=pDC->SelectObject(&pen); for(i=0;i;i+=4) { pDC->MoveTo(b[i].x,b[i... }
使用VC6++实现了图片旋转,方法简单,便于移植操作
VB通过调用DLL实现图片实时旋转,可360度旋转,掩码色改变,甚至可以调整图片透明度、亮度、色相、饱和度、大小缩放等图片常用的值。程序很好的解决了GetDC引起内存泄露问题,兼容Win98至Win7环境。Dll文件由VC生成...
vc 6.0实现的图片翻转特效,打开一幅BMP图片,点击编辑菜单中的“翻转”菜单,图片即可翻转。类似图片旋转。本源码可了解一些图片的简单解析操作,适合VC 初学者学习参考。
数字图像旋转,关于BMP格式图像的任意角度旋转 VC源码
opencv实现图像的旋转 旋转后的图像保持不变,可以更改背景颜色,利用专门的封装好的函数cvWarpAffine来实现。
CImage类源代码(C++) 可以使用该类直接对图片处理,可以任意角度旋转
VC 程序调用GDI+接口,处理各种类型的图片进行显示和其他效果处理,使用前需要注意GDI的资源初始化,退出程序要注意是否GDI 资源。 本程序附带简单的使用说明。需要单独下载GDIPLUS.
课程设计主要功能 (1)实现立方体的旋转功能 (2)实现立方体的透明效果 (3)实现立方体与图片的映射效果 (4)实现光源的照射效果 里面有个文档,一定要注意查看,否则很可能编译不成功
VC MVC写的图片查看器,浏览查看图片用的一个程序,基于MVC的设计理念完成,包括了完整的VC 源代码。本毕业设计中内含设计文档:开题报告.doc、基于MFC的图片浏览器的设计与实现.ppt。编写时候的几个关键技术及难点...
VC源程序大全 256色转灰度图.rar Hough变换.rar Walsh变换.rar 中值滤波.rar 二值化变换.rar 亮度增减.rar 傅立叶变换.rar 反色.rar 取对数.rar 取指数.rar 图像平移.rar 图像旋转.rar 图像细化.rar 图像缩放.rar ...