vb 图片翻转(水平和竖直)函数代码

我需要一个图片翻转函数要求:不允许添加任何控件,代码是放到模块里的,可以定义StdPicture类型来放图片,翻转包括水平和数值代码该如何编写呢?我都想了一天了,一点思路... 我需要一个图片翻转函数
要求:不允许添加任何控件,代码是放到模块里的,可以定义StdPicture类型来放图片,翻转包括水平和数值
代码 该如何编写呢?我都想了一天了,一点思路有没有啊!
着急急急急急急急急急急急!
展开
 我来答
szqaly
2015-08-05 · TA获得超过1745个赞
知道大有可为答主
回答量:2107
采纳率:77%
帮助的人:1528万
展开全部
'把图像读取到字节数组中进行处理:
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
banjinjiu33
2018-01-24
知道答主
回答量:1
采纳率:0%
帮助的人:907
引用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 Sub Command1_Click()
Set pic = LoadPicture("d:\psu1.jpg")
ReverseImage pic, True
End Sub
提示错误,怎么改?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式