VB image 旋转 90的代码
发布网友
发布时间:2023-08-10 14:34
我来回答
共2个回答
热心网友
时间:2024-08-26 09:23
先设一个长整型数组,然后用Point函数逐像素把图片读入数组,然后用循环把数组中的元素旋转90度,可以把结果放入另一个数组中,最后把结果用Pset函数输出。数组的边界值可以根据图片的高和宽得到,多试几次,并不难。
嗯,刚去看了有关位图文件的结构的文章,最简单的BMP也要好好研究一下才能读写,就别说楼主还没有限定图形文件的格式了,如果再涉及到压缩,那就不是一个小的课题了。
热心网友
时间:2024-08-26 09:24
Option Explicit
Const Pi = 3.14
Private Sub CommandRototate_Click()
Dim x As Integer, y As Integer
Dim X1 As Integer, Y1 As Integer
Dim X2 As Double, Y2 As Double
Dim X3 As Double, Y3 As Double
Dim JiaoDu As Double
Dim HuDu As Double
JiaoDu = 90 '角度
HuDu = JiaoDu * Pi / 180 '弧度
PicSource.ScaleMode = vbPixels
PicTarget.ScaleMode = vbPixels
For x = 0 To PicTarget.ScaleWidth
X1 = x - PicTarget.ScaleWidth \ 2
For y = 0 To PicTarget.ScaleHeight
Y1 = y - PicTarget.ScaleHeight \ 2
X2 = X1 * Cos(-HuDu) + Y1 * Sin(-HuDu)
Y2 = Y1 * Cos(-HuDu) - X1 * Sin(-HuDu)
X3 = X2 + PicSource.ScaleWidth \ 2
Y3 = Y2 + PicSource.ScaleHeight \ 2
If X3 > 0 And X3 < PicSource.ScaleWidth - 1 And Y3 > 0 And Y3 <
PicSource.ScaleHeight - 1 Then
PicTarget.PSet (x, y), PicSource.Point(X3, Y3)
End If
Next y
Next x
End Sub
以上是纯计算的代码。如果要最求速度请用GDI+的相关模块(图片矩阵)