GDI+ standard library 1.45 by tic

Post your working scripts, libraries and tools
Posts: 75
Joined: 27 Apr 2016, 23:40

Re: GDI+ standard library 1.45 by tic

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 (19.36 KiB) Viewed 257 times
test code

Code: Select all

#SingleInstance, Force
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)

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

	If !pToken := Gdip_Startup()
		MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
	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!
	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)


	SelectObject(hdc, obm)
Posts: 3162
Joined: 09 Oct 2013, 10:31

Re: GDI+ standard library 1.45 by tic

25 Jan 2021, 22:03

iseahound wrote:
25 Jan 2021, 17:56

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

Posts: 861
Joined: 12 Aug 2014, 12:37

Re: GDI+ standard library 1.45 by tic

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.
Posts: 634
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: GDI+ standard library 1.45 by tic

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
Posts: 75
Joined: 27 Apr 2016, 23:40

Re: GDI+ standard library 1.45 by tic

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.
Posts: 744
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania

Re: GDI+ standard library 1.45 by tic

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.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: RicKami and 25 guests