vb 图片翻转(水平和竖直)函数代码
我需要一个图片翻转函数要求:不允许添加任何控件,代码是放到模块里的,可以定义StdPicture类型来放图片,翻转包括水平和数值代码该如何编写呢?我都想了一天了,一点思路...
我需要一个图片翻转函数
要求:不允许添加任何控件,代码是放到模块里的,可以定义StdPicture类型来放图片,翻转包括水平和数值
代码 该如何编写呢?我都想了一天了,一点思路有没有啊!
着急急急急急急急急急急急! 展开
要求:不允许添加任何控件,代码是放到模块里的,可以定义StdPicture类型来放图片,翻转包括水平和数值
代码 该如何编写呢?我都想了一天了,一点思路有没有啊!
着急急急急急急急急急急急! 展开
展开全部
'把图像读取到字节数组中进行处理:
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private 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
Sub ReverseImage(img As StdPicture, Optional UpDownOrLeftRight As Boolean = False)
With img
Dim BmpInfo As Bitmap
GetObject .Handle, Len(BmpInfo), BmpInfo
Dim BytesPixel As Integer
BytesPixel = BmpInfo.bmBitsPixel / 8
Dim Bits() As Byte
ReDim Bits(BmpInfo.bmWidthBytes - 1, BmpInfo.bmHeight - 1)
GetBitmapBits .Handle, BmpInfo.bmWidthBytes * BmpInfo.bmHeight, Bits(0, 0)
Dim rBits() As Byte
ReDim rBits(BmpInfo.bmWidthBytes - 1, BmpInfo.bmHeight - 1)
Dim Y As Integer, X As Integer
Dim p As Integer
If UpDownOrLeftRight Then
Dim rR As Integer, sR As Integer
For Y = BmpInfo.bmHeight - 1 To 0 Step -1
rR = BmpInfo.bmHeight - 1 - Y
For X = 0 To BmpInfo.bmWidthBytes - 1
rBits(X, rR) = Bits(X, Y)
Next X
Next Y
Else
Dim rIndex As Integer
Dim sIndex As Integer
For Y = 0 To BmpInfo.bmHeight - 1
For X = BmpInfo.bmWidth - 1 To 0 Step -1
sIndex = X * BytesPixel
rIndex = (BmpInfo.bmWidth - 1 - X) * BytesPixel
For p = sIndex To sIndex + 2
rBits(rIndex, Y) = Bits(p, Y)
rIndex = rIndex + 1
Next
Next X
Next Y
End If
Call SetBitmapBits(.Handle, BmpInfo.bmWidthBytes * BmpInfo.bmHeight, rBits(0, 0))
End With
End Sub
引用szqaly的回答:
'把图像读取到字节数组中进行处理:Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As LongPrivate Type Bitmap bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As LongEnd TypeSub ReverseImage(img As StdPicture, Optional UpDownOrLeftRight As Boolean = False) With img Dim BmpInfo As Bitmap GetObject .Handle, Len(BmpInfo), BmpInfo Dim BytesPixel As Integer BytesPixel = BmpInfo.bmBitsPixel / 8 Dim Bits() As Byte ReDim Bits(BmpInfo.bmWidthBytes - 1, BmpInfo.bmHeight - 1) GetBitmapBits .Handle, BmpInfo.bmWidthBytes * BmpInfo.bmHeight, Bits(0, 0) Dim rBits() As Byte ReDim rBits(BmpInfo.bmWidthBytes - 1, BmpInfo.bmHeight - 1) Dim Y As Integer, X As Integer Dim p As Integer If UpDownOrLeftRight Then Dim rR As Integer, sR As Integer For Y = BmpInfo.bmHeight - 1 To 0 Step -1 rR = BmpInfo.bmHeight - 1 - Y For X = 0 To BmpInfo.bmWidthBytes - 1 rBits(X, rR) = Bits(X, Y) Next X Next Y Else Dim rIndex As Integer Dim sIndex As Integer For Y = 0 To BmpInfo.bmHeight - 1 For X = BmpInfo.bmWidth - 1 To 0 Step -1 sIndex = X * BytesPixel rIndex = (BmpInfo.bmWidth - 1 - X) * BytesPixel For p = sIndex To sIndex + 2 rBits(rIndex, Y) = Bits(p, Y) rIndex = rIndex + 1 Next Next X Next Y End If Call SetBitmapBits(.Handle, BmpInfo.bmWidthBytes * BmpInfo.bmHeight, rBits(0, 0)) End WithEnd Sub
'把图像读取到字节数组中进行处理:Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As LongPrivate Type Bitmap bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As LongEnd TypeSub ReverseImage(img As StdPicture, Optional UpDownOrLeftRight As Boolean = False) With img Dim BmpInfo As Bitmap GetObject .Handle, Len(BmpInfo), BmpInfo Dim BytesPixel As Integer BytesPixel = BmpInfo.bmBitsPixel / 8 Dim Bits() As Byte ReDim Bits(BmpInfo.bmWidthBytes - 1, BmpInfo.bmHeight - 1) GetBitmapBits .Handle, BmpInfo.bmWidthBytes * BmpInfo.bmHeight, Bits(0, 0) Dim rBits() As Byte ReDim rBits(BmpInfo.bmWidthBytes - 1, BmpInfo.bmHeight - 1) Dim Y As Integer, X As Integer Dim p As Integer If UpDownOrLeftRight Then Dim rR As Integer, sR As Integer For Y = BmpInfo.bmHeight - 1 To 0 Step -1 rR = BmpInfo.bmHeight - 1 - Y For X = 0 To BmpInfo.bmWidthBytes - 1 rBits(X, rR) = Bits(X, Y) Next X Next Y Else Dim rIndex As Integer Dim sIndex As Integer For Y = 0 To BmpInfo.bmHeight - 1 For X = BmpInfo.bmWidth - 1 To 0 Step -1 sIndex = X * BytesPixel rIndex = (BmpInfo.bmWidth - 1 - X) * BytesPixel For p = sIndex To sIndex + 2 rBits(rIndex, Y) = Bits(p, Y) rIndex = rIndex + 1 Next Next X Next Y End If Call SetBitmapBits(.Handle, BmpInfo.bmWidthBytes * BmpInfo.bmHeight, rBits(0, 0)) End WithEnd Sub
展开全部
大侠,你好!
Private Sub Command1_Click()
Set pic = LoadPicture("d:\psu1.jpg")
ReverseImage pic, True
End Sub
提示错误,怎么改?
Private Sub Command1_Click()
Set pic = LoadPicture("d:\psu1.jpg")
ReverseImage pic, True
End Sub
提示错误,怎么改?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询