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
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
引用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
提示错误,怎么改?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询