我需要做一下简单的图象处理。
问题如下:
1、我需要将Picture控件中的图片的像素全部放到数组中。
2、根据数组中的像素值来处理图片,如增亮、变暗等。请问该如何做啊,最好有源代码,小妹妹很笨。
各位哥哥,小妹我先谢谢你们了,我会感谢你们的!

解决方案 »

  1.   

    Picture中的图像读取后都是32位的,处理起来很方便。可以直接用GetDibBits各道图像的数组数据。
    增亮、变暗就是算法的问题了,简单增亮的就如 :   NewRed=IIF(Red+Para>255,255,Red+Para>)
      

  2.   

    网上有很多例子。你google一下。搜索"carles p.v.",此人写了很多关于图像处理的VB程序。
      

  3.   

    http://www.vbgood.com/viewthread.php?tid=51212&extra=page%3D1模拟PS中的曲线功能的控件,并附有图像处理的代码!
      

  4.   

    各位大哥,帮忙看看,我参考网上的代码,可是Picture2不是显示的Picture1的图片,而是显示的窗口左上角,是怎么回事?很急啊
    以下是源代码:Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    '删除一个对象
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    '选择当前对象
    Private Declare Function GetCurrentObject Lib "gdi32" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
    '获取DIB
    Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BitMapInfo, ByVal wUsage As Long) As Long
    '获取系统时间
    Private Declare Function timeGetTime Lib "winmm.dll" () As Long'DIB输出Private Declare Function SetDIBitsToDevice Lib "gdi32.dll" (ByVal hdc As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal dwWidth As Long, ByVal dwHeight As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal uStartScan As Long, ByVal cScanLines As Long, lpvBits As Any, lpbmi As Any, ByVal fuColorUse As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long)'数据结构定义:
    Private Type BitMapInfoHeader '文件信息头——BITMAPINFOHEADER
       biSize As Long
       biWidth As Long
       biHeight As Long
       biPlanes As Integer
       biBitCount As Integer
       biCompression As Long
       biSizeImage As Long
       biXPelsPerMeter As Long
       biYPelsPerMeter As Long
       biClrUsed As Long
       biClrImportant As Long
    End TypePrivate Type RGBQuad
            rgbBlue As Byte
            rgbGreen As Byte
            rgbRed As Byte
            'rgbReserved As Byte
    End TypePrivate Type BitMapInfo
            bmiHeader As BitMapInfoHeader
            bmiColors As RGBQuad
    End TypePrivate Type ColorChart
       ColorCount(255) As Long   '统计原来图片中的亮度出现次数
       PixcelCount As Long           '记录图片的像素个数
       ColRatio(255) As Single      '记录每一个亮度的出现比例
       NewVal(255) As Byte         '存放新的亮度索引
    End Type
    Dim ColChart As ColorChart'这三个数据结构都是在DIB中不可缺少的。我们不必深究,只是按照顺序复制粘贴直接使用就是了。'过程中用到的全局变量:
    Private Const Bits As Long = 32  '颜色深度,这里把所有图像都按照32位来处理
    Public Done As Boolean              '用于标记一个过程是否结束
    Public TimeGet As Long              '用于记录输入过程处理所花费的时间
    Public TimePut As Long              '用于记录输出过程处理所花费的时间
    Dim bBytes() As Byte
    Dim ColVal() As Byte                 '用于存放从DIB输入的像素值
    Dim ColOut() As Byte                 '用于存放向DIB输出的像素值
    Dim InPutHei As Long                 '用于记录输入图像的高度
    Dim InPutWid As Long                '用于记录输入图像的宽度
    Dim OutPutHei As Long                 '用于记录输入图像的高度
    Dim OutPutWid As Long                '用于记录输入图像的宽度
    Dim bi24BitInfo As BitMapInfo    '定义BMP信息'''过程一: 获得一个在PICTURE控件中打开的图像的所有像素?
    Public Sub DibGet(ByVal IdSource As Long, XBegin As Long, ByVal YBegin As Long, ByVal XEnd As Long, ByVal YEnd As Long, Optional Enhance As Boolean = False)
    Dim iBitmap As Long
    Dim iDC As Long
    Dim I As Long
    Dim L As Long
    Dim X As Long
    Dim Y As Long
    Dim W As Long
    Dim H As Long
    Dim Total As Long
    Dim AlignedW As Long 'in bytes  '$$$$$$$$$$$$$$$$$
    'On Error GoTo ErrLine
    Done = False
    TimeProcess = timeGetTime
    InPutWid = XEnd - XBegin
    InPutHei = YEnd - YBegin
    OutPutHei = InPutHei
    OutPutWid = InPutWid
    W = InPutWid + 1
    H = InPutHei + 1
    'AlignedW = ((W * 3& + 3&) And (Not 3&))
    I = (Bits \ 8) - 1ReDim ColVal(I, InPutWid, InPutHei)With bi24BitInfo.bmiHeader
       .biBitCount = Bits
       .biCompression = 0&
       .biPlanes = 1
       .biSize = Len(bi24BitInfo.bmiHeader)
       .biWidth = W
       .biHeight = H
    End With
    iBitmap = GetCurrentObject(IdSource, 7)
    GetDIBits IdSource, iBitmap, 0, H, ColVal(0, 0, 0), bi24BitInfo, 0
    'DeleteObject iBitmapCanZoom = True
    CanPut = True
    Done = True
    TimeProcess = timeGetTime - TimeProcess
    Exit Sub
    ErrLine:
      MsgBox "错误号:" & Err.Number & ":" & Err.Description
    End Sub
    Public Sub DIBPut(ByVal IdDestination As Long)
    Dim W As Long
    Dim H As LongOn Error GoTo ErrLine
    Done = False
    TimePut = timeGetTimeW = OutPutWid + 1H = OutPutHei + 1With bi24BitInfo.bmiHeader
       .biWidth = W
      .biHeight = H
       LineBytes = ((W * Bits + 31) And &HFFFFFFE0) \ 8
       .biSizeImage = LineBytes * H
    End WithSetDIBitsToDevice IdDestination, 0, 0, W, H, 0, 0, 0, H, ColOut(0, 0, 0), bi24BitInfo.bmiHeader, 0Done = True
    TimePut = timeGetTime - TimePut
    Exit Sub
    ErrLine:
    MsgBox Err.Description
    End Sub
    '''用于数组整体移动数据的过程:
    Public Sub CopyData(ByVal W As Long, ByVal H As Long)
    Dim Length As Long
    Dim I As Long
    Dim L As Long
    I = Bits \ 8
    L = I - 1
     Length = (W + 1&) * (H + 1&) * I
    ReDim ColOut(L, W, H)
    CopyMemory ColOut(0, 0, 0), ColVal(0, 0, 0), Length
    End Sub
    Sub command1_click()
    With Picture1
       .ScaleMode = 3
       .BorderStyle = 0
       DibGet .hdc, 0, 0, .ScaleWidth, .ScaleHeight
    End With
    CopyData InPutHei, InPutWid
    Picture2.AutoRedraw = True
    DIBPut Picture2.hdcPicture2.RefreshEnd Sub
      

  5.   

    以上的代码不用看,最好把你调用的代码贴出来,感觉是你调用上出了问题.
    其次,你看一下你的PICTURE控件的SCALEMODE,是否设为PIXEL了,如果这个属性设置不正确的话,就取不到正确大小的图像.
      

  6.   

    to WallesCai
    以上代码就是所有代码,可是Picture2不是显示的Picture1的图片,而是显示的窗口左上角,是怎么回事
      

  7.   

    DibGet Picture1.hdc, 0, 0, Picture1.Width - 1, Picture1.Height - 1
    把这句拿到WITH外面来试试,我感觉是hdc没有传过去,你可以在这句上加个断电,运行的时候看一下hdc是否为0
    如果不为0则说明正确,如果为0则取到桌面上去了
      

  8.   

    还有,PCITURE1的AUTOREDRAW也设为TRUE
      

  9.   

    WallesCai大哥 谢谢啦,这个问题已经解决了,还得打扰一下,我PCITURE2显示前对图片像素做一下处理(改变像素值),如何实现呢?
      

  10.   

    WallesCai大哥 谢谢啦,这个问题已经解决了,还得打扰一下,我想再PCITURE2显示前对图片像素做一下处理(改变像素值),如何实现呢?
      

  11.   

    http://blog.yesky.com/blog/wallescai/default.aspx?pg=1
    里面看