pixelsearch Posted June 5 Posted June 5 (edited) Hello everybody @UEZ explained in track ticket 4098 why plenty of graphics context disappear in the examples of the help file, he also gave a solution to prevent this. Here are a couple of tests done on some help file examples : 1) Topic _GDIPlus_LineBrushCreate (original code) The graphics context disappear if you minimize the GUI OR drag the GUI outside the screen bounds OR cover the GUI with another window : #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Example() Func Example() _GDIPlus_Startup() ;initialize GDI+ Local Const $iWidth = 600, $iHeight = 600, $iBgColor = 0x303030 ;$iBgColor format RRGGBB Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI GUISetBkColor($iBgColor, $hGUI) ;set GUI background color GUISetState(@SW_SHOW) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) Local $hBrush = _GDIPlus_LineBrushCreate(0, 0, 280, 500, 0xFFFF0000, 0xFF4020FF, 1) ;create linear gradient brush _GDIPlus_GraphicsFillEllipse($hGraphics, 100, 50, 380, 500, $hBrush) ;draw the egg Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ;cleanup GDI+ resources _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) EndFunc ;==>Example 2) Same topic _GDIPlus_LineBrushCreate (reworked code) 7 lines added in 2 groups (3+4 lines) * 1st group of 3 lines just before original Local $hGraphics = ... (this line to be commented out or deleted) * 2nd group of 4 lines just before the main loop expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> Example() Func Example() _GDIPlus_Startup() ;initialize GDI+ Local Const $iWidth = 600, $iHeight = 600, $iBgColor = 0x303030 ;$iBgColor format RRGGBB Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI GUISetBkColor($iBgColor, $hGUI) ;set GUI background color GUISetState(@SW_SHOW) ;============ 1st part to keep graphics context showing (3 lines added) ============ Local $idPic = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight) Local $hImageScan0 = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImageScan0) ;=================================================================================== ;;;;; Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle ; <=== LINE REMOVED _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) Local $hBrush = _GDIPlus_LineBrushCreate(0, 0, 280, 500, 0xFFFF0000, 0xFF4020FF, 1) ;create linear gradient brush _GDIPlus_GraphicsFillEllipse($hGraphics, 100, 50, 380, 500, $hBrush) ;draw the egg ;============ 2nd part to keep graphics context showing (4 lines added) ============ Local $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageScan0) _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, 0x0172, 0, $hBitmap_GDI)) ; $STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0 _WinAPI_DeleteObject($hBitmap_GDI) _GDIPlus_ImageDispose($hImageScan0) ;=================================================================================== Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ;cleanup GDI+ resources _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) EndFunc ;==>Example Now the graphics context never disappear ! I immediately tried this on another example of the help file : 3) Topic _GDIPlus_LineBrushSetSigmaBlend (reworked code) Exactly the same 7 lines added in 2 groups (3+4 lines) and the original Local $hGraphics = ... commented out (or deleted) expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> Example() Func Example() _GDIPlus_Startup() ;initialize GDI+ Local Const $iWidth = 600, $iHeight = 300, $iBgColor = 0x303030 ;$iBgColor format RRGGBB Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI GUISetBkColor($iBgColor, $hGUI) ;set GUI background color GUISetState(@SW_SHOW) ;============ 1st part to keep graphics context showing (3 lines added) ============ Local $idPic = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight) Local $hImageScan0 = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImageScan0) ;=================================================================================== ;;;;; Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle ; <=== LINE REMOVED _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) Local $hBrush = _GDIPlus_LineBrushCreate(0, 0, 0, 280, 0xFFFFFF00, 0xFF0000FF, 1) ;create line brush _GDIPlus_GraphicsFillRect($hGraphics, 10, 10, 280, 280, $hBrush) ;draw the filled rectangle _GDIPlus_LineBrushSetSigmaBlend($hBrush, 0.333, .85) _GDIPlus_GraphicsFillRect($hGraphics, 310, 10, 280, 280, $hBrush) ;draw the filled rectangle _GDIPlus_GraphicsDrawString($hGraphics, "w/o sigma blend", 14, 14) _GDIPlus_GraphicsDrawString($hGraphics, "w/ sigma blend", 314, 14) ;============ 2nd part to keep graphics context showing (4 lines added) ============ Local $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageScan0) _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, 0x0172, 0, $hBitmap_GDI)) ; $STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0 _WinAPI_DeleteObject($hBitmap_GDI) _GDIPlus_ImageDispose($hImageScan0) ;=================================================================================== Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ;cleanup GDI+ resources _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) EndFunc ;==>Example This should help users who need their graphics context to be always shown. All credits go to UEZ. Edited June 5 by pixelsearch typo WildByDesign and ioa747 2 "I think you are searching a bug where there is no bug... don't listen to bad advice."
jpm Posted Tuesday at 03:02 PM Posted Tuesday at 03:02 PM (edited) Thanks what the solution for _GDIPlus_DrawImageFXEx() Quote #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> _Example() Func _Example() If Not _GDIPlus_Startup() Or @extended < 6 Then MsgBox($MB_SYSTEMMODAL, "ERROR", "GDIPlus.dll v1.1 not available") Return EndIf Local $sFile = FileOpenDialog("Select an image", "", "Images (*.bmp;*.png;*.jpg;*.gif;*.tif)") If @error Or Not FileExists($sFile) Then Return Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) Local $iWidth = 600 Local $iHeight = _GDIPlus_ImageGetHeight($hImage) * 600 / _GDIPlus_ImageGetWidth($hImage) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iWidth, $iHeight) _GDIPlus_GraphicsDispose($hContext) Local $hGui = GUICreate("GDI+ v1.1 (" & @ScriptName & ")", $iWidth, $iHeight) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui) GUISetState(@SW_SHOW) Local $hEffect = _GDIPlus_EffectCreate($GDIP_HueSaturationLightnessEffectGuid) Local $tEffectParameters = DllStructCreate($tagGDIP_EFFECTPARAMS_HueSaturationLightness) Local $fW, $fH For $i = 1 To 140 DllStructSetData($tEffectParameters, "HueLevel", Random(-180, 180, 1)) _GDIPlus_EffectSetParameters($hEffect, $tEffectParameters) $fW = Random(20, 100) $fH = Random(20, 100) _GDIPlus_DrawImageFXEx($hGraphics, $hBitmap, $hEffect, Random(0, $iWidth - $fW), Random(0, $iHeight - $fH), $fW, $fH) Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_EffectDispose($hEffect) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() EndFunc ;==>_Example Edited Tuesday at 03:03 PM by jpm
mLipok Posted Tuesday at 06:24 PM Posted Tuesday at 06:24 PM (edited) Sorry if I interrupt but I think I had similar problem in the past (still not solved) with my: expandcollapse popupFunc _QPDF_Display(ByRef $oQP, $sPDF_Display_Comment = '', $iLeft = -1, $iTop = 0, $iWidth = 600, $iSelectPage = 1) __QPDF_IsUnlocked($oQP) If @error Then Return SetError(@error, @extended, $QPDF_RET_FAILURE) Local $sPDF_Display_Title = 'QuickPDF Test Display: ' & $sPDF_Display_Comment ; select Page If $iSelectPage = -1 Then $iSelectPage = $oQP.PageCount $oQP.SelectPage($iSelectPage) ; ; @TODO _QPDF_SetDefaultCoordinates($oQP) _QPDF_SetDefaultCoordinates($oQP) ;~ $oQP.SetOrigin($QPDF_SORIGIN_BottomLeft) ;~ $oQP.SetMeasurementUnits($QPDF_MUNITS_Milimeters) $oQP.NormalizePage(0) $oQP.CombineContentStreams() $oQP.SelectContentStream(1) ; Local $sOutput ; $sOutput &= BinaryToString($oQP.GetContentStreamToVariant()) & @CRLF ; $oQP.SelectContentStream(1) ; calculate DPI Local $iPageWidth = $oQP.PageWidth() Local $iPageHeight = $oQP.PageHeight() ; Local $iInches = $iPageWidth / 72 Local $iDisplayDPI = ($iWidth / $iPageWidth) * 72 / 3 ; create GUI Local $iHeight = ($iWidth * $iPageHeight) / $iPageWidth Local $hWND_QP_TestDisplay = GUICreate($sPDF_Display_Title, $iWidth, $iHeight, $iLeft, $iTop) Local $hDC = _WinAPI_GetDC($hWND_QP_TestDisplay) GUISetState(@SW_SHOW) ; render QP object to Device Context $oQP.RenderPageToDC($iDisplayDPI, $iSelectPage, $hDC) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _WinAPI_ReleaseDC($hWND_QP_TestDisplay, $hDC) GUIDelete($hWND_QP_TestDisplay) ; Deletes a GUI window and all controls that it contains. EndFunc ;==>_QPDF_Display This example just create window, get DC and than render QP object to Device Context. ; create GUI Local $iHeight = ($iWidth * $iPageHeight) / $iPageWidth Local $hWND_QP_TestDisplay = GUICreate($sPDF_Display_Title, $iWidth, $iHeight, $iLeft, $iTop) Local $hDC = _WinAPI_GetDC($hWND_QP_TestDisplay) GUISetState(@SW_SHOW) ; render QP object to Device Context $oQP.RenderPageToDC($iDisplayDPI, $iSelectPage, $hDC) But maybe this is not the same issue. But in any case I could open separate topic for this issue and help request. Edited Tuesday at 06:25 PM by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
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