IanN1990 Posted December 2, 2012 Share Posted December 2, 2012 (edited) This is code taken from the HelpFile. #include #include _Main() Func _Main() Local $hBitmap, $hClone, $hImage, $iX, $iY ; Initialize GDI+ library _GDIPlus_Startup() ; Capture 32 bit bitmap $hBitmap = _ScreenCapture_Capture("") $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) ; Create 24 bit bitmap clone $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF24RGB) ; Save bitmap to file _GDIPlus_ImageSaveToFile($hClone, @MyDocumentsDir & "\GDIPlus_Image.bmp") ; Clean up resources _GDIPlus_ImageDispose($hClone) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() EndFunc ;==>_Main Am i able to use _WinAPI_GetObject() on $hClone, in order to find out its Size ? If i am correct, could someone help me do it I have never been very good with WInAPIs and GetObject has no example for me to twinker with. *Edit. Thanks to Uez for answering my problem Edited December 4, 2012 by IanN1990 Link to comment Share on other sites More sharing options...
Malkey Posted December 2, 2012 Share Posted December 2, 2012 This is code taken from the HelpFile. #include #include _Main() Func _Main() Local $hBitmap, $hClone, $hImage, $iX, $iY ; Initialize GDI+ library _GDIPlus_Startup() ; Capture 32 bit bitmap $hBitmap = _ScreenCapture_Capture("") $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) ; Create 24 bit bitmap clone $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF24RGB) ; Save bitmap to file _GDIPlus_ImageSaveToFile($hClone, @MyDocumentsDir & "GDIPlus_Image.bmp") ; Clean up resources _GDIPlus_ImageDispose($hClone) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() EndFunc ;==>_Main Am i able to use _WinAPI_GetObject() on $hClone, in order to find out its Size ? If i am correct, could someone help me do it I have never been very good with WInAPIs and GetObject has no example for me to twinker with. Given the example script, it is obvious the required size is not the width and the height you are after. The only other size I can think of is in kilobytes. See this example. expandcollapse popup#include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> _Main() Func _Main() Local $hBitmap, $hClone, $hImage, $iX, $iY ; Initialize GDI+ library _GDIPlus_Startup() ; Capture 32 bit bitmap $hBitmap = _ScreenCapture_Capture("") $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) ; Create 24 bit bitmap clone $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) ConsoleWrite("$hImage " & $iX & " X " & $iY & @LF) $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, 600, 400, $GDIP_PXF24RGB) $iX = _GDIPlus_ImageGetWidth($hClone) $iY = _GDIPlus_ImageGetHeight($hClone) ConsoleWrite("$hClone " & $iX & " X " & $iY & @LF) ConsoleWrite($iX * $iY * 3 / 2 ^ 10 & "KB" & @LF) ; Save bitmap to file _GDIPlus_ImageSaveToFile($hClone, @MyDocumentsDir & "GDIPlus_Image.bmp") ConsoleWrite(FileGetSize(@MyDocumentsDir & "GDIPlus_Image.bmp") / 2 ^ 10 & "KB" & @LF) ; Clean up resources _GDIPlus_ImageDispose($hClone) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBitmap) ShellExecute(@MyDocumentsDir & "GDIPlus_Image.bmp") ; Shut down GDI+ library _GDIPlus_Shutdown() EndFunc ;==>_Main Link to comment Share on other sites More sharing options...
IanN1990 Posted December 2, 2012 Author Share Posted December 2, 2012 Is there no way to get the size of the file when it is memory ? I want to make a popup saying "The file will be X Size, are you sure u want to save" but your way the file has already been created Link to comment Share on other sites More sharing options...
UEZ Posted December 2, 2012 Share Posted December 2, 2012 (edited) You can stream the image into memory using one of the image formats (jpg, bmp, png, gif, tif) and get thus the size it uses in the memory. expandcollapse popup#include <GDIPlus.au3> #include <Memory.au3> _GDIPlus_Startup() Global $sFile = StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUImsoobe.jpg") Global $hBitmap = _GDIPlus_ScaleImage($sFile, 102, 76) Global $bImage = _GDIPlus_SaveImage2BinaryString($hBitmap, 50, True, @ScriptDir & "Test.jpg") MsgBox(0, "Binary", $bImage & @LF & @LF & "File lenght: " & BinaryLen($bImage) & " bytes") _GDIPlus_Shutdown() Func _GDIPlus_SaveImage2BinaryString($hBitmap, $iQuality = 50, $bSave = False, $sFilename = "Converted.jpg") ;coded by Andreik, modified by UEZ Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("jpg") Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Local $pEncoder = DllStructGetPtr($tGUID) Local $tParams = _GDIPlus_ParamInit(1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local $pParams = DllStructGetPtr($tParams) Local $hStream = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", 0, "bool", True, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/ms864401.aspx If @error Then Return SetError(1, 0, 0) $hStream = $hStream[3] DllCall($ghGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $hBitmap, "ptr", $hStream, "ptr", $pEncoder, "ptr", $pParams) _GDIPlus_BitmapDispose($hBitmap) Local $hMemory = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $hStream, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx If @error Then Return SetError(2, 0, 0) $hMemory = $hMemory[2] Local $iMemSize = _MemGlobalSize($hMemory) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data;ptr") Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) If $bSave Then Local $hFile = FileOpen($sFilename, 18) FileWrite($hFile, $bData) FileClose($hFile) EndIf Return $bData EndFunc ;==>_GDIPlus_SaveImage2BinaryString Func _GDIPlus_ScaleImage($sFile, $iW, $iH, $iInterpolationMode = 7) ;coded by UEZ 2012 If Not FileExists($sFile) Then Return SetError(1, 0, 0) Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then Return SetError(2, 0, 0) Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) If @error Then Return SetError(3, 0, 0) $hBitmap = $hBitmap[6] Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode) _GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iW, $iH) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hBmpCtxt) Return $hBitmap EndFunc ;==>_GDIPlus_ScaleImage Br, UEZ Edited December 2, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now