VB 如何用 LoadBitmap 和 LoadImage 打开图片?
在VB 6.0中, 如何用API的 LoadBitmap 函数 和 LoadImage 函数 打开图片,并把图片显示在Picture1中?(不能使用LoadPicture函数)
追问:很好,能打开 bmp 格式的图片,但jpg图片怎么打开?
在VB 6.0中, 如何用API的 LoadBitmap 函数 和 LoadImage 函数 打开图片,并把图片显示在Picture1中?(不能使用LoadPicture函数)
追问:很好,能打开 bmp 格式的图片,但jpg图片怎么打开?
答案:Const LR_LOADFROMFILE = &H10
Const IMAGE_BITMAP = 0
Const IMAGE_ICON = 1
Const IMAGE_CURSOR = 2
Const IMAGE_ENHMETAFILE = 3
Const CF_BITMAP = 2
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
Private Sub Form_Load()
Dim hDC As Long, hBitmap As Long
'Load the bitmap into the memory
hBitmap = LoadImage(App.hInstance, "d:\pintu\p1.bmp", IMAGE_BITMAP, 400, 290, LR_LOADFROMFILE)
If hBitmap = 0 Then
MsgBox "There was an error while loading the bitmap"
Exit Sub
End If
'open the clipboard
OpenClipboard Me.hwnd
'Clear the clipboard
EmptyClipboard
'Put our bitmap onto the clipboard
SetClipboardData CF_BITMAP, hBitmap
'Check if there's a bitmap on the clipboard
If IsClipboardFormatAvailable(CF_BITMAP) = 0 Then
MsgBox "There was an error while pasting the bitmap to the clipboard!"
End If
'Close the clipboard
CloseClipboard
'Get the picture from the clipboard
Me.Picture = Clipboard.GetData(vbCFBitmap)
End SubGod
楼主非要动用 API 来解决问题吗
楼主您的问题本质上就是:导入自定义资源到指定的位置 (我是这么理解的)
那您有没有考虑过 利用 VB的资源管理器 来实现呢?
思路:
1.您可以在编程阶段利用 VB的资源管理器 导入您需要的自定义资源到 .res (工程资源文件)
至于是什么自定义资源 那就随便您了
我知道的哪怕是 DLL 动态的Gif 声音 视频... 都是能够被封装到 .res 内部的
对于JPEG的图片我想是小菜
当然对于特殊的资源导出到程序中,比如 动态的Gif ,您想让他动起来还是要特定的“容器”的,我推荐用
Webrowser 控件做这个 Gif的 容器
还有如果PictureBox不允许加载 JPG 那用Webrowser 试试
2.编写事件调用 .res 中的内容
我想对于 VB资源管理器 来说,除了认识 BMP 或者是ICO 少数几种格式的图片,其它格式的东西一概会被认为是 “自定义资源”或者说是二进制文件
S() = LoadResData(101, "custom")
就这么简单的一句,VB已经帮助您完成了二进制文件一切的一切,那么就避开了那些VB不擅长做的
二进制算法
补充
如果我理解错了,就当我什么都没说
如果希望了解,欢迎追问