7,763
社区成员
发帖
与我相关
我的任务
分享
'本程序演示将JPG文件显示在picture1中,并将picture1保存到一维数组中,再将一维数组还原成图像到picture2中
'在Form1上添加2个图片框picture1、picture2,1个命令按钮command1
'事先在picture1中装入一张JPG图片,picture2.width=picture1.width,然后picture2.height=picture1.height
Option Explicit
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
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
Dim PictureBits() As Byte, PictureInfo As BITMAP, iBit As Long
Private Sub Form_Load()
Picture1.Picture = LoadPicture("d:\131431.jpg")
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
End Sub
Private Sub Command1_Click()
GetObject Picture1.Image, Len(PictureInfo), PictureInfo
ReDim PictureBits(1 To PictureInfo.bmWidthBytes * PictureInfo.bmHeight) As Byte
GetBitmapBits Picture1.Image, UBound(PictureBits), PictureBits(1)
SetBitmapBits Picture2.Image, UBound(PictureBits), PictureBits(1) '将数组还原成图像
Picture2.Refresh
End Sub