请问:怎样把 PictureBox 中的图像读写到一维数组中?又怎样把一维数组恢复成图像?

解决方案 »

  1.   

    你可以先用savepicture把图片保存到文件里,在一维数组中保存文件名,恢复时重新
    loadpicture就可以了
      

  2.   

    用savepicture把图片保存到临时目录的文件中,然后使用二进制格式打开,保存到数据中,恢复的时候,将数组中数据保存到文件中,然后使用loadpicture导入到PictureBox中。
      

  3.   

    zhouxiaotan(周晓潭) :
    就这样啦?
      

  4.   

    你可以把数组定义成 StdPicture  或 Picture 
    然后 用 set 命令
    如:
    Dim aa(1) As StdPictureSet aa(0) = Picture1.PicturePicture2.Picture = aa(0)
      

  5.   

    TO yefm(百聊) :
    如果不用StdPicture对象,而使用Byte数组,该如何做呢?
    我没研究过,真心请教. :)
      

  6.   

    TO:Cooly(☆开心就好 ^o^ ☆) 以下是我的思路,未曾试过
    1、定义一个结构
      Type Tbit
        bit() As Byte
      End Type2、定义一个Tbit类型的数组
       Dim myPic(1) As Tbit3、把图片框中的图片保存一个文件,然后
      Open FileName For Binary As #1
      ReDim myPic(0).bit(LOF(1)) As Byte
      Get 1, 1, myPic(0).bit 
      Close 1
      

  7.   

    TO yefm(百聊)::)
    你说的方法我知道,不过我需要的是不用文件操作,也就是说我不保存文件,直接从picturebox读取图片信息,然后保存在一个Byte数组里面.
      

  8.   

    哪位高手能解决(不保存文件,直接从picturebox读取图片信息,然后保存在一个Byte数组里面)?
      

  9.   

    用savepicture把图片保存到文件里,在一维数组中保存文件名,用时用
    loadpicture就可以了
      

  10.   

    我有这样一个想法:在内存中建立一个区域,把picturebox的图像像保存文件一样保存进去,然后再读取成数组。这种方法至少要比在硬盘上保存然后读取快的多。哪位高手能够实现呀?
      

  11.   

    取得PictureBox内BitMap图的各个Bytehttp://www.zjonline.com.cn/vbbible/software/program/vb/ccw/htmapi35.htm
      

  12.   

    以下是楼上给的地址的内容:取得PictureBox内BitMap图的各个Byte
    来源:cww'Form 中有PictureBox并指定好图形,另一CommandBoxPrivate Declare Function GetObject Lib "gdi32" Alias "GetObjectA" _
            (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) _
            As Long
    Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, _
            ByVal dwCount As Long, lpBits 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 Long
    End TypePrivate Sub Command1_Click()
    Dim hBitmap As Long
    Dim res As Long
    Dim bmp As BITMAP
    Dim byteAry() As Byte
    Dim totbyte As Long, i As Long
    hBitmap = Picture1.Picture.Handleres = GetObject(hBitmap, Len(bmp), bmp) '取得BitMap的结构totbyte = bmp.bmWidthBytes * bmp.bmHeight '总共要多少个Byte来存图ReDim byteAry(totbyte - 1)
    '将该图全放进ByteAry中
    res = GetBitmapBits(hBitmap, totbyte, byteAry(0))Debug.Print "Total Bytes Copied :"; res
    Debug.Print "bmp.bmBits "; bmp.bmBits
    Debug.Print "bmp.bmBitsPixel "; bmp.bmBitsPixel '每个Pixel需多少Bits莱表现
    Debug.Print "bmp.bmHeight "; bmp.bmHeight       'bitmap图的高是多少Pixels
    Debug.Print "bmp.bmPlanes "; bmp.bmPlanes
    Debug.Print "bmp.bmType "; bmp.bmType            
    Debug.Print "bmp.bmWidth "; bmp.bmWidth         'BitMap图宽为多少pixels     
    Debug.Print "bmp.bmWidthBytes "; bmp.bmWidthBytes  '每条扫描线需多少Byte来存
    End Sub
      

  13.   

    上面的代码是要求事先装载一个图片,如果PictureBox中的图像是自行绘制的,是否就无法实现了?
      

  14.   

    晕哦!!
    用GetBitmapBits或者GetDIBBits来取得
    用SetBitmapBits或者SetDIBBits或者StretchDIBBits来设置啊
      

  15.   

    to thirdapple(陨落雕)
        能给点代码吗?谢谢。
      

  16.   

    TO thirdapple(陨落雕) :
    哈,把你给忘了。 :)我的需求是用PictureBox做手写容器,然后读取手写内容并保存在一个数组中,通过socket发送到服务器端并以binary方式保存在数据库中。现在问题就出在如何读取手写内容。bmp格式即可(灰度).
      

  17.   

    了解下bmp格式就可以了,包括头部信息,bmp信息,灰度的有个调色版,后面用一个字节表示一中灰度
      

  18.   

    bmp格式我已经了解,现在主要是不太清楚如何能够得到PictureBox中用Line方法绘制的图形信息.
      

  19.   

    手写的?看我的手写识别,里面用了快速读取Picture内容到数组的方法,其实很简单的:
    http://www.fantasiasoft.net/myocr.zip
    因为读取到数组的方法只有在图象处理的时候有用,所以没有单独写这个模块,搞图象处理都没有用到PictureBox框:)
      

  20.   

    thirdapple(陨落雕) 已经说得够明白了,按他说的做吧
      

  21.   

    'Create a new project, add a command button and a picture box to the project, load a picture into the picture box.
    'Paste this code into Form1
    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
    Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    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
    Dim PicBits() As Byte, PicInfo As BITMAP, Cnt As Long
    Private Sub Command1_Click()
        'Get information (such as height and width) about the picturebox
        GetObject Picture1.Image, Len(PicInfo), PicInfo
        'reallocate storage space
        ReDim PicBits(1 To PicInfo.bmWidthBytes * PicInfo.bmHeight) As Byte
        'Copy the bitmapbits to the array
        GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
        'Invert the bits
        For Cnt = 1 To UBound(PicBits)
            PicBits(Cnt) = 255 - PicBits(Cnt)
        Next Cnt
        'Set the bits back to the picture
        SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
        'refresh
        Picture1.Refresh
    End Sub