4 posts in this topic
Hello all . i'm trying to build a tool to generate some pictures/graphs automatically based on some variables. I have completed the first part and I'm struggling now on what I thought would be the easiest part :
In my tool there is a "preview" button, which helps to display on a new children GUI the generated picture. What I do in simplified :
Global $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;Then, I'll add multiple objects to this graphic, for example $Temp = _GDIPlus_ImageLoadFromFile($temp) _GDIPlus_GraphicsDrawImage($g_hGraphics,$temp)
I'm then able to have a preview GUI showing all my elements perfectly. This works but now I want to be able to really generate it and have a ".png" file written to disk.
What I tried without success:
$g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($previewWidth, $previewHeight, $g_hGraphics) _GDIPlus_ImageSaveToFile($g_hBitmap,$OUTPUTDIR & "\generated\test-"&@HOUR&@MIN&@SEC&".png") But what I write to file is a transparent PNG without anything.
I'm pretty sure I'm missing something obvious there, I need your help
NB : If this change your answer, my goal will be to generate transparent png, meaning I'll add multiple objects/pictures/texts on a transparent png background and if there are some "transparent holes" I need them to be transparent in the generated png.
Thanks a lot for any help !
If you set within a window, a given color as transparent, every area of that window painted with that color, act as an hole through wich you can see what's behind, and click on what's behind as well.
Here, for example, is a simple effect of fishes swimming around on the screen.
#include <WinAPI.au3> #include <WindowsConstants.au3> #include <Misc.au3> ; for _IsPressed (23 END key) Local $hDLL = DllOpen("user32.dll"), $oIE = ObjCreate("Shell.Explorer.2") Local $hBackground = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUPWINDOW, $WS_EX_LAYERED + $WS_EX_TOPMOST) Local $AlphaKey = 0xF0F7FF ; everything with color $AlphaKey within this window will be transparent ; even if within an embedded browser control!..... _WinAPI_SetLayeredWindowAttributes($hBackground, $AlphaKey, 0, $LWA_COLORKEY) GUISetState(@SW_SHOW, $hBackground) $hIE = GUICtrlCreateObj($oIE, 0, 0, @DesktopWidth, @DesktopHeight) ; <- embedd $oIE in the AutoIt GUI GUISetBkColor($AlphaKey, $hBackground) ; $AlphaKey $hBackground transparent $oIE.navigate('http://cdn.abowman.com/widgets/fish/fish.swf') ; $oIE.navigate('http://cdn.abowman.com/widgets/spider/spider.swf') ; a spider goes around on the screen .... ; !! to use the spider.swf, you need to set $AlphaKey = 0xffffff on line 7 "! While True If _IsPressed("23", $hDLL) Then ExitLoop ; END key was pressed Sleep(250) WEnd $oIE = "" $hDLL = "" GUIDelete($hBackground)
I'm trying to do something simple, but I can't manage to find where to start since I can have multiple possibilities and not sure what is the best one :
Taking screen capture (I can do that) On this capture, I'll look for 10 particular regions that will give me 10 images of 40px * 40px (I can do that) Then what I want is for each of these regions, find on my library of ~140 images which one is the closest one to my region (= the match)
What do you think is the best approach ? Ican easily do step 1 and 2, however for the third step :
I can't use memcmp because they won't be exactly the same (original library can differ a very little bit from what I'll get from my screen capture) There is no text, only drawing Should I do a pixelSum of what I get on screen and do the same via GDIPlus for each of my images in the library?
Thanks a lot,
When I try to add blur to an Image with _GDIPlus_EffectCreateBlur and _GDIPlus_BitmapApplyEffect the blur is only horizontal, not horizontal and vertical, if the blur radius is <= 20.
Easy to test with the Image I attached and the default example from the helpfile of
_GDIPlus_BitmapApplyEffect The second Image I attached is the result and as you can see the cross is only blurred in one direction. Does anyone have a clue why this happens and furthermore a solution for this problem? (I could just rotate the picture but then it would be twice as time consuming...)
Thanks in advance,
p.s.: Running Win 10 Pro with all updates
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=car.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GDIPlus.au3> #include <File.au3> #include <Array.au3> #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ProgressConstants.au3> ; Declare array Dim $Images ; Gets all JPG files in the current directory (@ScriptDir). Local $search = FileFindFirstFile("*.jpg") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No JPG files could be found.") Exit EndIf ; Resize array While 1 If IsArray($Images) Then Local $Bound = UBound($Images) ReDim $Images[$Bound+1] EndIf $Images[$Bound] = FileFindNextFile($search) If @error Then ExitLoop WEnd ; Close the search handle FileClose($search) ; Create directory "resized" if not there yet $nymappe = InputBox("Mappe / Bil Navn", "Mappe / Bil Navn") If NOT FileExists(@ScriptDir & "\" & $nymappe & "\") Then DirCreate(@ScriptDir & "\" & $nymappe & "\") EndIf ; Loop for JPGs - gets dimension of JPG and calls resize function to resize to 50% width and 50% height For $i = 1 to Ubound($Images)-1 If $Images[$i] <> "" AND FileExists(@ScriptDir & "\" & $Images[$i]) Then Local $ImagePath = @ScriptDir & "\" & $Images[$i] _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($ImagePath) Local $ImageWidth = _GDIPlus_ImageGetWidth($hImage) Local $ImageHeight = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ;MsgBox(0,"DEBUG", $ImageWidth & " x " & $ImageHeight) Local $NewImageWidth = ($ImageWidth / 100) * 15 Local $NewImageHeight = ($ImageHeight / 100) * 15 ;MsgBox(0,"DEBUG: " & $i,$Images[$i]) _ImageResize(@ScriptDir & "\" & $Images[$i], @ScriptDir & "\" & $nymappe & "\" & $Images[$i], $NewImageWidth, $NewImageHeight) EndIf Next ; Resize function Func _ImageResize($sInImage, $sOutImage, $iW, $iH) Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0 ;OutFile path, to use later on. Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1)) ;OutFile name, to use later on. Local $sOF = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1) ;OutFile extension , to use for the encoder later on. Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1)) ; Win api to create blank bitmap at the width and height to put your resized image on. $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) _WinAPI_ReleaseDC($hWnd, $hDC) ;Start GDIPlus _GDIPlus_Startup() ;Get the handle of blank bitmap you created above as an image $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP) ;Load the image you want to resize. $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage) ;Get the graphic context of the blank bitmap $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1) ;Draw the loaded image onto the blank bitmap at the size you want _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH) ;Get the encoder of to save the resized image in the format you want. $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image. Do $i += 1 Until (Not FileExists($sOP & $i & "_" & $sOF)) ;Prefix the number to the begining of the output filename $sOutImage = $sOP & $i & "_" & $sOF ;Save the new resized image. _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID) ;Clean up and shutdown GDIPlus. _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose ($hGraphic) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() EndFunc Quality gets quite bad compared to using Paint / Photoshop when resizing with GDIPlus
Any idea how to make the quality better?
Thanks in advance