1,_INetGetSource($Url, 0) 不写缓存直接获取二进制数据
2,通过二进制数据获取图像位图句柄(happytc 写 ...
afan 发表于 2012-1-3 23:15
这个方法还是要完全下载,只是不保存为文件,同是直接读内存操作
#include <Inet.au3>
#include <GDIPlus.au3>
$bImage = _INetGetSource('http://www.baidu.com/img/baidu_sylogo1.gif', False)
$hHBITMAP = Load_BMP_From_Mem($bImage, True)
_GDIPlus_Startup()
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
$iWidth = _GDIPlus_ImageGetWidth($hImage)
$iHeight = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_Shutdown()
MsgBox(0, 0, "Width: " & $iWidth & "; Height: " & $iHeight)
Func Load_BMP_From_Mem($mem_image, $hHBITMAP = False)
If Not IsBinary($mem_image) Then Return SetError(1, 0, 0)
Local $declared = True
If Not $ghGDIPDll Then
_GDIPlus_Startup()
$declared = False
EndIf
Local Const $memBitmap = Binary($mem_image)
Local Const $len = BinaryLen($memBitmap)
Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE)
Local Const $pData = _MemGlobalLock($hData)
Local $tMem = DllStructCreate("byte[" & $len & "]", $pData)
DllStructSetData($tMem, 1, $memBitmap)
_MemGlobalUnlock($hData)
Local $hStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0)
$hStream = $hStream[3]
Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0)
$hBitmap = $hBitmap[2]
Local Const $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _
"dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT))
$tMem = 0
If $hHBITMAP Then
Local Const $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_GDIPlus_BitmapDispose($hBitmap)
If Not $declared Then _GDIPlus_Shutdown()
Return $hHBmp
EndIf
If Not $declared Then _GDIPlus_Shutdown()
Return $hBitmap
EndFunc
|