Sub bmp_rotate(pic1 As PictureBox, pic2 As PictureBox, ByVal theta!) 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, 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
但是只能转90度和180度
我想转任意角度找不到方法imgedit没有提供对旋转任意角度的支持,只能自己写代码实现了
不用imgedit因为我已经将图片另存了
可以指定地址后单独对图片操作
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, 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
tif用PictureBox识别不了
zSin = Sin(zang)picW = Picture2.Width
picH = Picture2.Heightixc1 = Picture1.Width / 2: iyc1 = Picture1.Height / 2
ixc2 = Picture2.Width / 2: iyc2 = Picture2.Height / 2For iy = 1 To picH
For ix = 1 To picW
ixs = ixc1 + (ix - ixc2 - 1) * zCos + (iy - iyc2) * zSin
iys = iyc1 + (iy - iyc2) * zCos - (ix - ixc2 - 1) * zSin
LongCul(1) = GetPixel(Picture1.hdc, ixs, iys)
If LongCul(1) = -1 Then GoTo Nextix
ixs = ixc1 + (ix - ixc2 + 1) * zCos + (iy - iyc2) * zSin
iys = iyc1 + (iy - iyc2) * zCos - (ix - ixc2 + 1) * zSin
LongCul(2) = GetPixel(Picture1.hdc, ixs, iys)
If LongCul(2) = -1 Then GoTo Nextix
ixs = ixc1 + (ix - ixc2) * zCos + (iy - iyc2 + 1) * zSin
iys = iyc1 + (iy - iyc2 + 1) * zCos - (ix - ixc2) * zSin
LongCul(3) = GetPixel(Picture1.hdc, ixs, iys)
If LongCul(3) = -1 Then GoTo Nextix ixs = ixc1 + (ix - ixc2) * zCos + (iy - iyc2 - 1) * zSin
iys = iyc1 + (iy - iyc2 - 1) * zCos - (ix - ixc2) * zSin
LongCul(4) = GetPixel(Picture1.hdc, ixs, iys)
If LongCul(4) = -1 Then GoTo Nextix
SMOOTH LongCulAV
res& = SetPixelV(Picture2.hdc, ix, iy, LongCulAV)
Nextix:
Next ix
Next iy