GDI+ standard library 1.45 by tic

Post your working scripts, libraries and tools for AHK v1.1 and older
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: GDI+ standard library 1.45 by tic

Post by iseahound » 07 Jan 2022, 11:15

There should be one here:

https://github.com/buliasz/AHKv2-Gdip

I was hoping buliasz would post it himself.

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: GDI+ standard library 1.45 by tic

Post by boiler » 07 Jan 2022, 11:32

Wasn't aware that had been created. That's good to know.

neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: GDI+ standard library 1.45 by tic

Post by neogna2 » 25 Jan 2022, 11:47

For google findability: the buliasz github file is a v2 version of the Gdip_All.ahk GDI+ library that is compatible with AutoHotKey v2.beta3 .
This is worth mentioning because some other posts and versions in the v2 forums are not compatible with v2.beta3.
Another v2.beta3 compatible version is by TheArkive at github and AHK forum. It also contains C++ source for the mcode.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: GDI+ standard library 1.45 by tic

Post by iseahound » 27 Jan 2022, 19:25

@robodesign Someone came to me with a modification of one of my functions, and it appears that it is incorrectly changed. Please see the last below.

viewtopic.php?f=76&t=99406

robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: GDI+ standard library 1.45 by tic

Post by robodesign » 30 Jan 2022, 14:00

iseahound wrote:
27 Jan 2022, 19:25
@robodesign Someone came to me with a modification of one of my functions, and it appears that it is incorrectly changed. Please see the last below.

viewtopic.php?f=76&t=99406
After repeated tests... your claims seem to be unfounded and easily to refute. They were hastly formulated. Please download/use the latest version of the library. Your functions were not broken.

But thank you for signaling a potential bug.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

BobGT
Posts: 1
Joined: 15 May 2022, 18:00

Re: GDI+ standard library 1.45 by tic

Post by BobGT » 18 May 2022, 21:31

For the Gdip_BitmapFromHWND , it casued flicker under win11 with high frequency call . changed the PrintWindow with bitblt , it works without flicker.

Code: Select all

Gdip_BitmapFromHWND(hwnd)
{
	WinGetPos,,, Width, Height, ahk_id %hwnd%
	hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
	RegExMatch(A_OsVersion, "\d+", Version)
	PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0)
	pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
	SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
	return pBitmap
}

foxhunter
Posts: 72
Joined: 04 Aug 2016, 04:27

Re: GDI+ standard library 1.45 by tic

Post by foxhunter » 26 Nov 2022, 01:23

I have a strange issue:
Using old Gdip_All_dropbox.ahk the script works, but updating to the new version on github it saves a black screenshot (with correct width/height)
I am using AHK 1.1.35.00 with Win7 32 bit.
Could please give a a hand?
Thank you.

Code: Select all

;dont work, black output:
#include Gdip_All.ahk    ; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation

;works:
;#include Gdip_All_dropbox.ahk ; https://www.dropbox.com/s/0e9gdfetbfa8v0o/Gdip_All.ahk

hwnd:=WinExist("ahk_exe msedge.exe")
if (hwnd)
{
	msgbox hwnd=%hwnd%  ; hwnd=0x1b0a50
	
	ptok := Gdip_startup()
	;win1 := Gdip_BitmapFromScreen( "hwnd:" . hwnd ) ; Note: always works 
	win1 := Gdip_BitmapFromHWND( hwnd)
	msgbox Result Gdip_BitmapFromHWND: %win1%  ; Result Gdip_BitmapFromHWND: 25436720

	save1:=Gdip_SaveBitmapToFile(win1,"win1.PNG")
	msgbox result Save= %save1%  ; result Save= 0

	Gdip_disposeImage( win1 )
	Gdip_shutdown(ptok)
}

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: GDI+ standard library 1.45 by tic

Post by boiler » 26 Nov 2022, 02:39

In the Gdip_BitmapFromHWND() function, replace this line:

Code: Select all

	PrintWindow(hwnd, hdc)
…to these:

Code: Select all

	RegExMatch(A_OsVersion, "\d+", Version)
	PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0)

robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: GDI+ standard library 1.45 by tic

Post by robodesign » 26 Nov 2022, 08:02

boiler wrote:
26 Nov 2022, 02:39
In the Gdip_BitmapFromHWND() function, replace this line:

Code: Select all

	PrintWindow(hwnd, hdc)
…to these:

Code: Select all

	RegExMatch(A_OsVersion, "\d+", Version)
	PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0)
I'll fix this. Thank you.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

Sam_
Posts: 146
Joined: 20 Mar 2014, 20:24

Re: GDI+ standard library 1.45 by tic

Post by Sam_ » 21 Mar 2023, 15:25

I'm trying to test out the different InterpolationModes for resizing an image to be larger than the original. I'm using Gdip_ResizeBitmap() to do the resizing, but no matter what value I give it for InterpolationMode it creates identical results. Here's my code.

Code: Select all

OriginalFile:=A_ScriptDir "\bscckey00000.png"
RequestedWidth:=RequestedHeight:=64


InterpolationMode:=["Default","LowQuality","HighQuality","Bilinear","Bicubic","NearestNeighbor","HighQualityBilinear","HighQualityBicubic"]
InterpolationMode.RemoveAt(0)
MsgBox % st_printArr(InterpolationMode)


pToken:=Gdip_Startup()
For InterpMode,v1 in InterpolationMode
	{
	NewPath:=A_ScriptDir "\bscckey00000_" v1 ".bmp"
	pBitmapFile:=Gdip_CreateBitmapFromFile(OriginalFile) ; Get the bitmap of the original file
	pBitmap:=Gdip_ResizeBitmap(pBitmapFile,RequestedWidth,RequestedHeight,1,InterpMode,0x26200A)
	Gdip_DisposeImage(pBitmapFile)				; Delete the bitmap of the original image
	Gdip_SaveBitmapToFile(pBitmap,NewPath)		; Save the new bitmap to file
	Gdip_DisposeImage(pBitmap)					; Delete the new bitmap
	}

Gdip_Shutdown(pToken)
ExitApp


st_printArr(array, depth=5, indentLevel=""){
	list:=""
   for k,v in Array
   {
      list.= indentLevel "[" k "]"
      if (IsObject(v) && depth>1)
         list.="`r`n" st_printArr(v, depth-1, indentLevel . "    ")
      Else
         list.=" => " v
      list.="`r`n"
   }
   return rtrim(list)
}

#Include %A_ScriptDir%\lib\Gdip_All.ahk
However, swapping out the call to Gdip_ResizeBitmap() for the following seems to work fine. What am I missing?

Code: Select all

	pBitmap:=Gdip_CreateBitmap(RequestedWidth,RequestedHeight,0x26200A)	; Create a new 32-bit RGBA bitmap
	G:=Gdip_GraphicsFromImage(pBitmap)			; Get a pointer to the graphics of the bitmap
	Gdip_SetInterpolationMode(G,InterpMode)				; Set Interpolation Mode
	Gdip_DrawImage(G,pBitmapFile,0,0,RequestedWidth,RequestedHeight)		; Draw the original image onto the new bitmap
Also while I'm at it, would setting different SmoothingModes on the graphics have an effect on the resizing operation?

robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: GDI+ standard library 1.45 by tic

Post by robodesign » 21 Mar 2023, 17:12

I'm under the impression you are passing strings. Such as default, low quality and so on...

You must pass numbers, values. For example, 5 for lowest quality, 7 for highest.

Smoothing mode doesn't affect resizing of bitmaps.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

Sam_
Posts: 146
Joined: 20 Mar 2014, 20:24

Re: GDI+ standard library 1.45 by tic

Post by Sam_ » 21 Mar 2023, 17:44

robodesign wrote:
21 Mar 2023, 17:12
I'm under the impression you are passing strings. Such as default, low quality and so on...

You must pass numbers, values.
I'm passing the key from the array to the Gdip_ResizeBitma() function, which is a number, and using the value (human friendly term) in the file name. I have manipulated the array to start at index 0.
robodesign wrote:
21 Mar 2023, 17:12
Smoothing mode doesn't affect resizing of bitmaps.
Thanks.

Sam_
Posts: 146
Joined: 20 Mar 2014, 20:24

Re: GDI+ standard library 1.45 by tic

Post by Sam_ » 22 Mar 2023, 17:40

@robodesign
I haven't figured out what my issue with using Gdip_ResizeBitmap() with different values for InterpolationMode might be, but I have noticed that pBrush isn't always initialized but is always queried always queried when the pointer to the Graphics is successfully created (which throws a warning), and when it is created it is never deleted. I think the function is missing a call to Gdip_DeleteBrush(pBrush) in that case?

robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: GDI+ standard library 1.45 by tic

Post by robodesign » 23 Mar 2023, 15:32

Sam_ wrote:
22 Mar 2023, 17:40
@robodesign
I haven't figured out what my issue with using Gdip_ResizeBitmap() with different values for InterpolationMode might be, but I have noticed that pBrush isn't always initialized but is always queried always queried when the pointer to the Graphics is successfully created (which throws a warning), and when it is created it is never deleted. I think the function is missing a call to Gdip_DeleteBrush(pBrush) in that case?
Yes, you are correct. I omitted to delete the brush when bgrColor was provided.

I updated the library with numerous fixes and improvements, and new functions. Current version now is v1.94.

Please download it from:
https://github.com/marius-sucan/AHK-GDIp-Library-Compilation

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

Re: GDI+ standard library 1.45 by tic

Post by Flowgun » 18 Apr 2023, 06:43

When I used the library within a script that runs as admin, it always crashes at "Gdip_Shutdown(pToken)".
ChatGPT suggested "explicit library loading and unloading" by adding a line to the function, which made things work perfectly:

Code: Select all

Gdip_Shutdown(pToken) {
   hModule := DllCall("LoadLibrary", "Str", "gdiplus.dll")
   DllCall("GdiplusShutdown", "UPtr", pToken)
   DllCall("FreeLibrary", "UPtr", hModule)
   return 0
}

User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: GDI+ standard library 1.45 by tic

Post by KruschenZ » 19 Apr 2023, 06:21

Hi :)

idk but something is different in 1.94 for "Gdip_TextToGraphics()".
I get more or less random colors. If I use the complete 1.94 Version and change only the "Gdip_TextToGraphics()" back to 1.92 then everything is fine and works well with my own colors.

Strange thing...

I have no sample code, because it's to complex for the whole thing...
but I use this in my class:

Code: Select all

GDIp_Brush := GDIp_BrushCreateSolid( "0xFF" GUI_Color_FontControl )
, GDIp_TextToGraphics( GDIp_Graphic, This.Text, "s" This.Font_Size " Center R3 vCenter c" GDIp_Brush " x" This.GUI_Control_Size " y2", This.Font, This.GUI_Control_Width_2, This.GUI_Control_Height - 1 )
, GDIp_DeleteBrush( GDIp_Brush )
I can live with only replacing "Gdip_TextToGraphics()" and otherwise using 1.94. Just wanted to let you know here.

GreetingZ
KruschenZ

robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: GDI+ standard library 1.45 by tic

Post by robodesign » 19 Apr 2023, 07:08

Please offer a clear example. I'd be happy to fix the bug if there's one. Thank you.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: GDI+ standard library 1.45 by tic

Post by KruschenZ » 20 Apr 2023, 02:06

Hi @robodesign,

here I have a simple example for that:

with 1.94
grafik.png
grafik.png (4.4 KiB) Viewed 2090 times
with 1.92
grafik.png
grafik.png (4.42 KiB) Viewed 2090 times

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#Persistent
#SingleInstance, Force

#Include %A_LineFile%\..\Gdip_All.ahk

GDIp_Startup()


GUI_Color_FontNormal := "FF0000"
GUI_Color_FontControl := "EB0000"
GUI_Color_BG := "000000"
GUI_Color_BGControl := "141414"
GUI_Color_Border := "FF0000"



Gui, New
Gui, Default

Gui, Color, % GUI_Color_BG
Gui, Font, s12 c%GUI_Color_FontNormal% Arial
Gui, Add, Text,, ABC abc
Gui, Add, Picture, w100 h100 HwndH_Icon +BackgroundTrans Icon2, % A_WinDir "\System32\shell32.dll"


GDIp_BitMap := GDIp_CreateBitmap(100, 102)
GDIp_Graphic := GDIp_GraphicsFromImage( GDIp_BitMap )

;BackGround
	GDIp_Brush := GDIp_BrushCreateSolid( "0xFF" GUI_Color_BGControl )
	GDIp_FillRectangle( GDIp_Graphic, GDIp_Brush, 0, 0, 100, 101)
	GDIp_DeleteBrush( GDIp_Brush )

;Border
	GDIp_Pen := GDIp_CreatePen( "0xFF" GUI_Color_Border, 2 )
	GDIp_DrawRoundedRectangle( GDIp_Graphic, GDIp_Pen, 0, 0, 100, 102, 0 )
	GDIp_DeletePen( GDIp_Pen )

;Adding: Text
	GDIp_Brush := GDIp_BrushCreateSolid( "0xFF" GUI_Color_FontControl )
	GDIp_TextToGraphics( GDIp_Graphic, "This is a test.", "s13 Bold NoWrap vCenter c" GDIp_Brush " x2 y3 ", "Arial", 100, 99)
	GDIp_DeleteBrush( GDIp_Brush )

GDIp_DeleteGraphics( GDIp_Graphic )
Image_On := GDIp_CreateHBITMAPFromBitmap( GDIp_BitMap )
GDIp_DisposeImage( GDIp_BitMap )

SetImage( H_Icon, Image_On )


Gui, Show, w200 h200

Return


GuiEscape:
	GuiClose:
	ExitApp


Thank you :-)

GreetingZ
KruschenZ

robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: GDI+ standard library 1.45 by tic

Post by robodesign » 20 Apr 2023, 03:45

@KruschenZ . Thank you . The bug is fixed now. Please redownload the Gdip_All.ahk file from Github. It was a regression, my bad.

Thanks for the example.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: GDI+ standard library 1.45 by tic

Post by KruschenZ » 20 Apr 2023, 05:52

Hi @robodesign

it work's like a charm :-)

Thank you very much for the lightning fast fix

GreetingZ
KruschenZ

Post Reply

Return to “Scripts and Functions (v1)”