主题:怎么样用API打开图片??
hao1122
[专家分:140] 发布于 2010-01-14 21:34:00
怎么样用 API 函数打开文件"Picture.bmp"并显示出来窗口,在这个过程不要用图片框控件或其他控件!!
谢谢!!!!我会给分的。。。
可不可以用 API 打开图片文件然后用 BitBlt 函数显示呢????
回复列表 (共5个回复)
沙发
一江秋水 [专家分:9680] 发布于 2010-01-15 09:53:00
不用图片框控件或其他控件,那就是用系统自带的图片和传真查看器?
板凳
tanchuhan [专家分:15140] 发布于 2010-01-15 11:53:00
LoadImage
CreateCompatibleDC
SelectObject
Bitblt
SelectObject
DeleteDC
DeleteObject
3 楼
hao1122 [专家分:140] 发布于 2010-01-15 20:17:00
我是想用API函数把图片文件直接显示在窗体上,就像BitBlt函数那样把图像复制到窗体,谢谢!
4 楼
bcahzvip [专家分:6040] 发布于 2010-01-15 22:04:00
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private mPic As StdPicture
Private mMemDC As Long
Private Sub Form_Load()
Set mPic = LoadPicture("C:\WINDOWS\Coffee Bean.bmp")
mMemDC = CreateCompatibleDC(Me.hdc)
SelectObject mMemDC, mPic.Handle
Me.ScaleMode = ScaleModeConstants.vbPixels
End Sub
Private Sub Form_Paint()
BitBlt Me.hdc, 0, 0, Me.ScaleWidth, Me.ScaleHeight, mMemDC, 0, 0, vbSrcCopy
End Sub
Private Sub Form_Unload(Cancel As Integer)
DeleteDC mMemDC
End Sub
5 楼
hao1122 [专家分:140] 发布于 2010-01-16 11:33:00
谢谢大家的帮助,下面是我修改的,全都是用API函数,不知道还有什么需要修改,请大虾多多指教!!!
Option Explicit
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 BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
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 DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private mMemDC_1 As Long
Private Filehwnd_1 As Long
Private ObjectDC As Long
Private Sub Command1_Click()
BitBlt ObjectDC, 0, 0, 500, 500, mMemDC_1, 0, 0, vbSrcCopy
End Sub
Private Sub Form_Load()
Dim Path_1 As String
ObjectDC = Me.hdc
Path_1 = "C:\窗口1.bmp"
Filehwnd_1 = LoadImage(0, Path_1, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
mMemDC_1 = CreateCompatibleDC(ObjectDC)
SelectObject mMemDC_1, Filehwnd_1
End Sub
Private Sub Form_Unload(Cancel As Integer)
DeleteDC mMemDC_1
DeleteObject Filehwnd_1
End Sub
我来回复