http://www.csdn.net/expert/topic/562/562083.xml?temp=.3508722
解决方案 »
- 亲们,可以帮我看一下代码吗,详解一下吧 ,谢谢,急需
- 我晕倒,中文版的VB如此烂!
- 如何做打印预览?打印一个固定格式的聘任书!
- 关于IsEmpty函数的问题
- 简单问题
- 如何用datagrid来添加删除修改记录
- 解压一压缩文件 TF.zip
- 在VB中,如何将文件压缩后上传到远程FTP或HTTP。
- 哪位老大有videosoft vsprint7的中文资料呀,50元购买。呵呵
- 在一些oicq聊天室总有那么一群人脏话连篇,而且不听招呼,十分烦,有办有什么软件能把这些人随时踢出,并且不管他换什么名字都可识别,如果编程,其思路该是什么?希望大家谈一谈.
- 请问如何在VB中使图片旋转???
- 精通VB,欲求兼职,能够我生活费就可以
我这还有个 旋转 90 度的例子. 要简陋些.但原理一样.
供参考参考:
------------------------------------------------------------------
Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
' *********************************************
' Rotate fr_pic 90 degrees and place the result
' in to_pic. Both PictureBoxes should have
' AutoRedraw = True.
' *********************************************
Public Sub RotatePicture(fr_pic As PictureBox, to_pic As PictureBox)
Dim bm As BITMAP
Dim hbm As Long
Dim fr_bytes() As Byte
Dim to_bytes() As Byte
Dim fr_wid As Long
Dim fr_hgt As Long
Dim to_wid As Long
Dim to_hgt As Long
Dim X As Integer
Dim Y As Integer ' Make to_pic use fr_pic's color palette.
to_pic.Picture = fr_pic.Picture
' Get fr_pic's pixels.
hbm = fr_pic.Image
GetObject hbm, Len(bm), bm
fr_wid = bm.bmWidthBytes
fr_hgt = bm.bmHeight
ReDim fr_bytes(1 To fr_wid, 1 To fr_hgt)
GetBitmapBits hbm, fr_wid * fr_hgt, fr_bytes(1, 1)
' Bitmap widths must be even.
to_hgt = fr_wid
to_wid = fr_hgt
If to_wid Mod 2 = 1 Then to_wid = to_wid + 1
' Make room for to_pic's pixels.
ReDim to_bytes(1 To to_wid, 1 To to_hgt)
' Make to_pic the right size.
to_pic.Width = to_pic.Parent.ScaleX(fr_hgt, vbPixels, to_pic.Parent.ScaleMode) + _
to_pic.Width - to_pic.ScaleWidth
to_pic.Height = to_pic.Parent.ScaleY(fr_wid, vbPixels, to_pic.Parent.ScaleMode) + _
to_pic.Height - to_pic.ScaleHeight
' Copy the pixels.
For X = 1 To fr_wid
For Y = 1 To fr_hgt
to_bytes(fr_hgt - Y + 1, X) = fr_bytes(X, Y)
Next Y
Next X
' Set the pixels in to_pic.
SetBitmapBits to_pic.Image, _
fr_hgt * fr_wid, to_bytes(1, 1)
to_pic.Refresh ' Make the image permanent.
to_pic.Picture = to_pic.Image
End Sub
主 题: 如何使一个BMP的图象旋转任意角度,能告诉我一个具体算法吗?
作 者: spirit00 (精灵)
等 级:
信 誉 值: 97
所属论坛: Visual Basic
问题点数: 20
回复次数: 9
发表时间: 2002-4-1 17:02:54
如何使一个BMP的图象旋转任意角度,能告诉我一个具体算法吗?能写段代码吗?
Const Pi = 3.14159265359
Private Declare Function SetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer) As Long
Private Declare Function StretchBlt% Lib "GDI32" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal nWidth%, ByVal nHeight%, ByVal hSrcDC%, ByVal XSrc%, ByVal YSrc%, ByVal nSrcWidth%, ByVal nSrcHeight%, ByVal dwRop&)
Sub Form_Load()
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
End Sub
Sub Command1_Click()
'rotate Right 45 degrees
Picture2.Cls
Call bmp_rotate(Picture1, Picture2, -3.14 / 4)
End Sub
Sub Command2_Click()
'vertical convert
Picture2.Cls
px% = Picture1.ScaleWidth
py% = Picture1.ScaleHeight
retval% = StretchBlt(Picture2.hDC, 0, py%, px%, -py%, Picture1.hDC, 0, 0, px%, py%, SRCCOPY)
End Sub
Sub Command3_Click()
'rotate Left 45 degrees
Picture2.Cls
Call bmp_rotate(Picture1, Picture2, 3.14 / 4)
End Sub
Sub bmp_rotate(pic1 As PictureBox, pic2 As PictureBox, ByVal theta!)
' bmp_rotate(pic1, pic2, theta)
' Rotate the image in a picture box.
' pic1 is the picture box with the bitmap to rotate
' pic2 is the picture box to receive the rotated bitmap
' theta is the angle of rotation
Dim c1x As Integer, c1y As Integer
Dim c2x As Integer, c2y As Integer
Dim a As Single
Dim p1x As Integer, p1y As Integer
Dim p2x As Integer, p2y As Integer
Dim n As Integer
Dim r As Integer c1x = pic1.ScaleWidth \ 2
c1y = pic1.ScaleHeight \ 2
c2x = pic2.ScaleWidth \ 2
c2y = pic2.ScaleHeight \ 2 If c2x < c2y Then n = c2y Else n = c2x
n = n - 1
pic1hDC% = pic1.hDC
pic2hDC% = pic2.hDC
For p2x = 0 To n
For p2y = 0 To n
If p2x = 0 Then a = Pi / 2 Else a = Atn(p2y / p2x)
r = Sqr(1& * p2x * p2x + 1& * p2y * p2y)
p1x = r * Cos(a + theta!)
p1y = r * Sin(a + theta!)
c0& = GetPixel(pic1hDC%, c1x + p1x, c1y + p1y)
c1& = GetPixel(pic1hDC%, c1x - p1x, c1y - p1y)
c2& = GetPixel(pic1hDC%, c1x + p1y, c1y - p1x)
c3& = GetPixel(pic1hDC%, c1x - p1y, c1y + p1x)
If c0& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2x, c2y + p2y, c0&)
If c1& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2x, c2y - p2y, c1&)
If c2& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2y, c2y - p2x, c2&)
If c3& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2y, c2y + p2x, c3&)
Next
t% = DoEvents()
Next
End Sub