int WINAPI icePub_imgCircumgyrate(char *strImgFilename,char *strBmpFilename,int radian)
输入:strImgFilename 待处理图像文件名
strBmpFilename 结果bmp文件名
radian 旋转角袭敏慎拿闷度
输出:
typedef int (WINAPI ICEPUB_IMGCIRCUMGYRATE)(char *strImgFilename,char *strBmpFilename,int radian)
ICEPUB_IMGCIRCUMGYRATE *icePub_imgCircumgyrate = 0
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll")
if(hDLLDrv)
{
icePub_imgCircumgyrate=(ICEPUB_IMGCIRCUMGYRATE *)GetProcAddress(hDLLDrv,"icePub_imgCircumgyrate")
}
if(icePub_imgCircumgyrate)
{
icePub_imgCircumgyrate("a.jpg","a1.bmp",45)
icePub_imgCircumgyrate("d.png"拍敬, "d1.bmp",120)
}
if(hDLLDrv)
FreeLibrary(hDLLDrv)
Timer timer1//定枝乱时旋转和移动Graphics g//背景图的画图对象float x = 0//水平移动的初始位置private void pictureBox1_Click(object sender, EventArgs e){bmp=new Bitmap(@"..\..\1.bmp")background = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)//画在PictureBox上g = Graphics.FromImage(background)g.TranslateTransform(background.Width / 2, background.Height / 2)//移动一下中心点,画在背景的中央,好看些timer1 = new Timer()timer1.Interval = 100timer1.Tick += new EventHandler(timer1_Tick)timer1.Enabled = true}void timer1_Tick(object sender, EventArgs e){g.Clear(Color.Black)g.RotateTransform(10.0F)//每次旋转10度,实际上是画图坐标旋转g.DrawImage(bmp, -bmp.Width/2, -bmp.Height/2)//源图中心点和画图对象中心重合,自旋转效果,否则会以左上角为中心旋数败转Graphics gb=pictureBox1.CreateGraphics()x += 3.0f//水平移动效果,步长3像猛毕档素缩放用:StretchBlt图片任意角度翻转:HBITMAP CBarDemoView::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/180 * PI)
float sine = (float)sin(radians/180 * PI)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)-minySetWorldTransform( 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 )nWidth[m_count] = bm.bmWidth
nHeight[m_count] = bm.bmHeight// Restore DCs
::SelectObject( sourceDC.m_hDC, hbmOldSource )
::SelectObject( destDC.m_hDC, hbmOldDest )return hbmResult
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)