GDI+ standard library 1.45 by tic

Post your working scripts, libraries and tools for AHK v1.1 and older
tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

Re: GDI+ standard library 1.45 by tic

Post by tuzi » 25 Jan 2021, 21:20

@robodesign The function by just-me still not working well……
@iseahound Thank you, I read that post you provided and made some attempts, but the problem remains the same.
1.png
1.png (19.36 KiB) Viewed 5600 times
test code

Code: Select all

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

#Include, Gdip_All.ahk

gosub, init
			; Gdip_FillRoundedRectangle(G, pBrush, 0, 0, PicWidth-500, PicHeight, 20)
			Gdip_FillRoundedRectanglePath(G, pBrush, 0, 0, PicWidth-500, PicHeight, 20)
			UpdateLayeredWindow(hwnd1, hdc, 200, 200, DisplayAreaWidth, DisplayAreaHeight)
Return

Gdip_FillRoundedRectanglePath(pGraphics, pBrush, X, Y, W, H, R) {
   ; Create a GraphicsPath
   DllCall("Gdiplus.dll\GdipCreatePath", "UInt", 0, "PtrP", pPath)
   ; Create a rounded rectabgle
   D := (R * 2), W -= D, H -= D
   DllCall("Gdiplus.dll\GdipAddPathArc", "Ptr", pPath, "Float", X, "Float", Y, "Float", D, "Float", D, "Float", 180, "Float", 90)
   DllCall("Gdiplus.dll\GdipAddPathArc", "Ptr", pPath, "Float", X + W, "Float", Y, "Float", D, "Float", D, "Float", 270, "Float", 90)
   DllCall("Gdiplus.dll\GdipAddPathArc", "Ptr", pPath, "Float", X + W, "Float", Y + H, "Float", D, "Float", D, "Float", 0, "Float", 90)
   DllCall("Gdiplus.dll\GdipAddPathArc", "Ptr", pPath, "Float", X, "Float", Y + H, "Float", D, "Float", D, "Float", 90, "Float", 90)
   DllCall("Gdiplus.dll\GdipClosePathFigure", "Ptr", pPath)
   ; Fill the path
   RS := DllCall("Gdiplus.dll\GdipFillPath", "Ptr", pGraphics, "Ptr", pBrush, "Ptr", pPath)
   ; Free resources
   DllCall("Gdiplus.dll\GdipDeletePath", "Ptr", pPath)
   Return RS
}

init:
	If !pToken := Gdip_Startup()
	{
		MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
		ExitApp
	}
	OnExit, Exit

	Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs +Hwndhwnd1
	Gui, 1: Show, NA
	Loop, Files, %A_WinDir%\Web\WallPaper\*.jpg, R
		ImgPath := A_LoopFileLongPath
	pBitmap := Gdip_CreateBitmapFromFile(ImgPath)
	If !pBitmap
	{
		MsgBox, 48, WallPaper loading error!
		ExitApp
	}
	PicWidth := Gdip_GetImageWidth(pBitmap), PicHeight := Gdip_GetImageHeight(pBitmap)
	DisplayAreaWidth:=A_ScreenWidth, DisplayAreaHeight:=A_ScreenHeight

	hbm := CreateDIBSection(DisplayAreaWidth, DisplayAreaHeight)
	hdc := CreateCompatibleDC()
	obm := SelectObject(hdc, hbm)
	G := Gdip_GraphicsFromHDC(hdc)
	Gdip_SetInterpolationMode(G, 7)

	pBitmap:=Gdip_ResizeBitmap(pBitmap, PicWidth//3, PicHeight//3, 0)
	PicWidth := Gdip_GetImageWidth(pBitmap), PicHeight := Gdip_GetImageHeight(pBitmap)
	pBrush:= Gdip_CreateTextureBrush(pBitmap, WrapMode:=1)

Return

GuiClose:
GuiEscape:
Exit:
	SelectObject(hdc, obm)
	DeleteObject(hbm)
	DeleteDC(hdc)
	Gdip_DeleteGraphics(G)
	Gdip_DisposeImage(pBitmap)
	Gdip_Shutdown(pToken)
	ExitApp
Return

guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

Post by guest3456 » 25 Jan 2021, 22:03

iseahound wrote:
25 Jan 2021, 17:56
@ewerybody

malcev has some good screengrabbing code using DirectX that is much faster than both existing methods.
but afaik the directx methods only work for full screen.. you cannot grab windows that are underneath others


malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: GDI+ standard library 1.45 by tic

Post by malcev » 25 Jan 2021, 22:23

Yes, You are right.
But if Your target program use directx then You can inject dll into it and hook EndScene method.

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

Re: GDI+ standard library 1.45 by tic

Post by iseahound » 26 Jan 2021, 01:05

Set your pixel offset mode to true. The default is None.



; Set some general Graphics settings.

Code: Select all

         DllCall("gdiplus\GdipSetPixelOffsetMode",    "ptr",pGraphics, "int",2) ; Half pixel offset. (⬅️🔚🔙↩️you need this one)
         DllCall("gdiplus\GdipSetCompositingMode",    "ptr",pGraphics, "int",1) ; Overwrite/SourceCopy.
         DllCall("gdiplus\GdipSetCompositingQuality", "ptr",pGraphics, "int",0) ; AssumeLinear
         DllCall("gdiplus\GdipSetSmoothingMode",      "ptr",pGraphics, "int",0) ; No anti-alias.
         DllCall("gdiplus\GdipSetInterpolationMode",  "ptr",pGraphics, "int",7) ; HighQualityBicubic

tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

Re: GDI+ standard library 1.45 by tic

Post by tuzi » 27 Jan 2021, 00:15

@iseahound Thank you so much, the problem is solved. :D :D :bravo: :thumbup:

@robodesign I think we can add this to Gdip.Tutorial.7 and 8. :D :D
; Set the PixelOffsetMode to Half pixel offset = 2 to draw a perfect Rounded Rectangle
Gdip_SetPixelOffsetMode(G, 2)


so that people know how to draw perfectly rounded rectangles.

Although the problem of drawing perfectly rounded rectangles is not because of the Gdip_FillRoundedRectangle function, I think that it can still be replaced by justme's function, because it solves another bug.

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

Re: GDI+ standard library 1.45 by tic

Post by robodesign » 27 Jan 2021, 03:57

@tuzi . Thank you for letting me know . PixelOffset=2 also solves image resizing errors in GDI+, in particular when working with small resolution images.

I already have planned for months to release a new GDI+ library version with bug fixes and improvements, but i keep on post-poning it...I will get to it, eventually.

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.

Suiyen
Posts: 8
Joined: 07 Feb 2021, 14:51

Re: Biblioteca estándar GDI+ 1.45 por tic

Post by Suiyen » 14 Mar 2021, 20:25

@tic

Hey Tic, how are you? I'm new for this sites, sorry for my English.

I would like to know if there is any possibility that the Windows function (Invert colors), is applied by each application, program or window; and not about the entire system or screen ...

I have tried everything, from an app called "Negative Screen", another called "Easy Invert", hundreds of consulted forums and I can't find the solution. I'm a programmer but not very advanced in this specific kind of thing.

I also use AutoHotKey, and if there is any existing command to do this, PERSISTENTLY, it would be heaven!

I need it for an application that is impossible to put in dark mode.

If said app is placed in High Contrast, another Windows function, it looks horrible and does not allow me to work.

Inverting colors is the only viable way for this.

Is there an expert programmer to help me? Or teach a course on this?

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: GDI+ standard library 1.45 by tic

Post by malcev » 13 Aug 2021, 08:22

You can create Your own gui, use magnification api with it, check z-order of You program and place gui in front of it.

salihverensoy
Posts: 5
Joined: 13 Aug 2021, 13:05

Re: GDI+ standard library 1.45 by tic

Post by salihverensoy » 31 Aug 2021, 14:01

Dear Tariq Porter, is gdip.ahk free4business ? Can we use it in our company or is it only free-to-use-at-home ? I didn't find a license doku in github or ahk-forum. Thanks for replying, Salih Verensoy

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

Re: GDI+ standard library 1.45 by tic

Post by iseahound » 04 Oct 2021, 22:24

@guest3456

Have you considered separating the Autohotkey v1 and Autohotkey v2 versions of gdi+?

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

Re: GDI+ standard library 1.45 by tic

Post by robodesign » 05 Oct 2021, 15:00

@anyone

I updated the GDI+ library compilation to v1.88.

From v1.88 onwards all of the functions that rely on CreatePointsF() or AllocateBinArray() can now handle being given an array. Previously they handled only strings. I also added more functions: Gdip_GaussianBlur(), Gdip_FillRoundedRectanglePath(), Gdip_DrawRoundedRectanglePath() and others. It also sports various bug fixes and other minor improvements.

You can find it at https://github.com/marius-sucan/AHK-GDIp-Library-Compilation .

As a bonus, the repository now also contains a GDI library wrapper that is used in my own application [ Quick Picto Viewer ]. It is not complete, far from... but decided to publish it.

In the future, I will update this library to AHK v2.

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.

guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

Post by guest3456 » 05 Oct 2021, 19:35

iseahound wrote:
04 Oct 2021, 22:24
@guest3456

Have you considered separating the Autohotkey v1 and Autohotkey v2 versions of gdi+?
the original idea was to try to make the library backward compatible with both versions, kinda like a goalstick for other libs to try to follow

sadly i havent kept up with the conversions for v2beta release


jsong55
Posts: 253
Joined: 30 Mar 2021, 22:02

Re: GDI+ standard library 1.45 by tic

Post by jsong55 » 23 Dec 2021, 23:05

Can't seem to get the colors to work for this.

Can someone help explain how to convert normal 6 character HEX color code to ARGB

Code: Select all

pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromFile("C:\Users\abc\Downloads\Soft Blue and Red Cute Illustrated Christmas Card.png")
G := Gdip_GraphicsFromImage(pBitmap)
name:= "John"
Options:="x10p y10p w80p r4 Centre cF2FFE9 s20"
mcolor:="0x9C6846"
Options:="x120 y300 c" mcolor " r4 s70"
Gdip_TextToGraphics(G, "Merry Christmas " Name, Options, "Freestyle Script")
; Gdip_TextToGraphics(G, "Merry Christmas " Name, "x10 y10", "Arial")
Gdip_SaveBitmapToFile(pBitmap, outputfile:="C:\Users\abc\Downloads\Soft Blue and Red Cute Illustrated Christmas Card_Out.png")
Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)

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

Re: GDI+ standard library 1.45 by tic

Post by boiler » 24 Dec 2021, 01:51

jsong55 wrote: Can someone help explain how to convert normal 6 character HEX color code to ARGB
Just put FF in front of it (for fully opaque), and do not precede it with 0x:

Code: Select all

mcolor :="FF9C6846"
Looking at the code, the Gdip_TextToGraphics() function is expecting the color definition to not include 0x. It adds on the 0x itself.

jsong55
Posts: 253
Joined: 30 Mar 2021, 22:02

Re: GDI+ standard library 1.45 by tic

Post by jsong55 » 24 Dec 2021, 02:18

boiler wrote:
24 Dec 2021, 01:51
jsong55 wrote: Can someone help explain how to convert normal 6 character HEX color code to ARGB
Just put FF in front of it (for fully opaque), and do not precede it with 0x:

Code: Select all

mcolor :="FF9C6846"
Looking at the code, the Gdip_TextToGraphics() function is expecting the color definition to not include 0x. It adds on the 0x itself.
ah Thanks. Most of the internet uses RGBA not sure why here uses ARGB. By the way, know where I can find how to convert the opacity to "FF" or "CC" or intermediate values?

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

Re: GDI+ standard library 1.45 by tic

Post by boiler » 24 Dec 2021, 04:01

jsong55 wrote: know where I can find how to convert the opacity to "FF" or "CC" or intermediate values?
Not sure what you mean. If you wanted the opacity to be CC in the above example, it would just be:

Code: Select all

mcolor :="CC9C6846"
Are you asking about some other situation? Like if a variable already contained an ARGB color value and you wanted to change the opacity? Can you show an example of what you mean?

jsong55
Posts: 253
Joined: 30 Mar 2021, 22:02

Re: GDI+ standard library 1.45 by tic

Post by jsong55 » 25 Dec 2021, 22:52

Sorry wasn't clear. I was trying to find out what to put as the AA values for various opacity levels. Say opacity at 30%, 50%? 100% is "FF"

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

Re: GDI+ standard library 1.45 by tic

Post by boiler » 26 Dec 2021, 00:28

The values for the alpha channel range from 00 (fully transparent) to FF (fully opaque), which correspond to 0 to 255 in decimal format. If you want 30% opacity, multiply 255 by 0.3 (76.5, so round to 77) and use a decimal-to-hex converter (Google it) to get 4D for the hex value.

BartNijs
Posts: 5
Joined: 06 Jan 2022, 07:40

Re: GDI+ standard library 1.45 by tic

Post by BartNijs » 07 Jan 2022, 09:24

Does this not work with the latest AHK2 version?
When trying to run any of the examples I get plenty of errors.

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

Re: GDI+ standard library 1.45 by tic

Post by boiler » 07 Jan 2022, 09:35

No it is written in and for AHK v1. Most libraries that have been written for AHK to this point have not been translated to v2. The move to v2 allowed for major changes and improvements in the language by no longer requiring backward compatibility with v1 scripts.

Post Reply

Return to “Scripts and Functions (v1)”