你可以把数组定义成 StdPicture 或 Picture 然后 用 set 命令 如: Dim aa(1) As StdPictureSet aa(0) = Picture1.PicturePicture2.Picture = aa(0)
TO yefm(百聊) : 如果不用StdPicture对象,而使用Byte数组,该如何做呢? 我没研究过,真心请教. :)
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
TO yefm(百聊)::) 你说的方法我知道,不过我需要的是不用文件操作,也就是说我不保存文件,直接从picturebox读取图片信息,然后保存在一个Byte数组里面.
以下是楼上给的地址的内容:取得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
'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
loadpicture就可以了
就这样啦?
然后 用 set 命令
如:
Dim aa(1) As StdPictureSet aa(0) = Picture1.PicturePicture2.Picture = aa(0)
如果不用StdPicture对象,而使用Byte数组,该如何做呢?
我没研究过,真心请教. :)
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
你说的方法我知道,不过我需要的是不用文件操作,也就是说我不保存文件,直接从picturebox读取图片信息,然后保存在一个Byte数组里面.
loadpicture就可以了
来源: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
用GetBitmapBits或者GetDIBBits来取得
用SetBitmapBits或者SetDIBBits或者StretchDIBBits来设置啊
能给点代码吗?谢谢。
哈,把你给忘了。 :)我的需求是用PictureBox做手写容器,然后读取手写内容并保存在一个数组中,通过socket发送到服务器端并以binary方式保存在数据库中。现在问题就出在如何读取手写内容。bmp格式即可(灰度).
http://www.fantasiasoft.net/myocr.zip
因为读取到数组的方法只有在图象处理的时候有用,所以没有单独写这个模块,搞图象处理都没有用到PictureBox框:)
'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