24位的BMP图像的内容保存为字节数组后,如何显示在其他Picture控件中?我用 SetBitmapBits 显示出来的图像变形了。
我的方法如下:
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private gblByteAry() As Byte '图像文件的内容字节数组
Private Sub Form_Load()
ReDim gblPicBits(FileLen(App.Path & "\test.bmp") - 1)
Open App.Path & "\test.bmp" For Binary As #1
Get #1, 1, gblByteAry
Close #1
End Sub
Private Sub Command1_Click()
SetBitmapBits Picture1.Image, UBound(gblByteAry), gblByteAry(0)
End Sub
可是显示出来的图像发生了变形。我测试的图像是24位的BMP,宽和高都是8个像素。
这样做的目的是,我把所有程序需要的图像文件保存在一个我自己定义的二进制文件中,程序中需要图像时,不是用LoadPicture函数,而是从自定义的文件中读取文件内容的字节数组,再显示在Picture控件中。
我可以对图像的内容随意加密,一般人除了截屏,很难用得上我的图像。
找了一天,研究了SetBitmapBits、SetDIBits、OleLoadPicture,还有一个什么什么Device。没有找到好用的代码。
不需要原理,请给出代码。谢谢!