Private Sub LoadWithLoadImage(ByVal pic As PictureBox, _ ByVal file_name As String) Dim hbm As Long Dim wid As Long Dim hgt As Long Dim temp_dc As Long ' Load the image using LoadImage. wid = pic.ScaleX(pic.ScaleWidth, pic.ScaleMode, _ vbPixels) hgt = pic.ScaleY(pic.ScaleHeight, pic.ScaleMode, _ vbPixels) hbm = LoadImage(ByVal 0&, file_name, _ IMAGE_BITMAP, wid, hgt, LR_LOADFROMFILE) ' Make a device context to hold the picture. temp_dc = CreateCompatibleDC(0) SelectObject temp_dc, hbm ' Copy the picture into the PictureBox. BitBlt pic.hdc, 0, 0, wid, hgt, temp_dc, 0, 0, SRCCOPY ' Delete the DC and bitmap. DeleteDC temp_dc DeleteObject hbm ' Make the image permanent. pic.Picture = pic.Image End SubPrivate Sub Form_Load() Dim file_name As String file_name = App.Path If Right$(file_name, 1) <> "\" Then file_name = _ file_name & "\" ' Load using LoadPicture. imgUnaliased.Picture = LoadPicture(file_name & _ "HalfJack2.bmp") ' Load using LoadWithLoadImage. LoadWithLoadImage picAliased, file_name & _ "HalfJack2.bmp" ' Copy the picture to an Image control. imgCopy.Picture = picAliased.Picture ' Save the picture into a file. SavePicture picAliased.Picture, file_name & _ "HalfJack2_small.bmp" End Sub
ByVal file_name As String)
Dim hbm As Long
Dim wid As Long
Dim hgt As Long
Dim temp_dc As Long ' Load the image using LoadImage.
wid = pic.ScaleX(pic.ScaleWidth, pic.ScaleMode, _
vbPixels)
hgt = pic.ScaleY(pic.ScaleHeight, pic.ScaleMode, _
vbPixels)
hbm = LoadImage(ByVal 0&, file_name, _
IMAGE_BITMAP, wid, hgt, LR_LOADFROMFILE) ' Make a device context to hold the picture.
temp_dc = CreateCompatibleDC(0)
SelectObject temp_dc, hbm ' Copy the picture into the PictureBox.
BitBlt pic.hdc, 0, 0, wid, hgt, temp_dc, 0, 0, SRCCOPY ' Delete the DC and bitmap.
DeleteDC temp_dc
DeleteObject hbm ' Make the image permanent.
pic.Picture = pic.Image
End SubPrivate Sub Form_Load()
Dim file_name As String file_name = App.Path
If Right$(file_name, 1) <> "\" Then file_name = _
file_name & "\" ' Load using LoadPicture.
imgUnaliased.Picture = LoadPicture(file_name & _
"HalfJack2.bmp") ' Load using LoadWithLoadImage.
LoadWithLoadImage picAliased, file_name & _
"HalfJack2.bmp" ' Copy the picture to an Image control.
imgCopy.Picture = picAliased.Picture ' Save the picture into a file.
SavePicture picAliased.Picture, file_name & _
"HalfJack2_small.bmp"
End Sub
http://www.vb-helper.com/howto_antialias_with_loadimage_into_file.html
http://support.microsoft.com/default.aspx?scid=kb;EN-US;187568
If hBitmap = 0 Then
Err.Raise vbObjectError + 513, , "装载文件时发生了错误,请检查"
Exit Sub
End IfhdcSrc = CreateCompatibleDC(0)'将创建的位图选入屏幕备场景
SelectObject hdcSrc, hBitmap' Copy the picture into the PictureBox.
BitBlt pic.hdc, 0, 0, wid, hgt, hdcSrc, 0, 0, SRCCOPY