Getting started with GDI+ (the API, not the AHK script)

Discuss other programming languages besides AutoHotkey
Miguel7
Posts: 186
Joined: 08 Sep 2014, 07:06

Getting started with GDI+ (the API, not the AHK script)

02 Feb 2016, 22:49

Hi guys,

I'm working on a C++ program that uses GDI+, and I'm totally struggling. This is by far one of the most cryptic APIs I've ever worked with; documentation exists, but trying to learn off that is like trying to memorize Wikipedia's entire database. :lolno:

So I have 2 questions for all you GDI+ wizards out there:

1. Can anyone recommend a good tutorial for the GDI+ API?
I'm thinking less Wikipedia, more tutorial-like. Even if there is no clear-cut set of instructions or step-by-step explanations, at least a good high-level overview of what the main objects are (HDCs, Bitmap class, BitmapData class etc. etc. etc. etc. ) and how they are meant to interact with each other. If there really is no such material, and the only way is pouring over page after page on MSDN/Google and hoping for the best, then my next question would be:

2. How does gdip.ahk compare?
Some phenomenal mega-genius has already cracked the cipher that is GDI+, and even exposed it to AHK. That's fantastic, and thanks to whoever you are. :D

But the whole reason I'm using GDI+ for this project is it needs to be fast, and faster than PixelSearch and PixelGetColor can go. It's only reading the image (no writing), but getting all those pixels' colors takes time. My C++ program so far can read a 1000x500 bitmap into its memory in like 0.02 seconds. That's amazing, and that's the kind of speed we're talking about here. So how does gdip.ahk compare to that? I know C++ pretty well, but I've been rockin the AHK for over 2 years now - so if I can get this done in AHK that would be awesome. :D

Thanks.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Getting started with GDI+ (the API, not the AHK script)

03 Feb 2016, 16:14

Well the main difference between the C++ Version and our AutoHotkey Version, is that we use functions, where as the Library uses a class based system.
You can divide into several groups.

One group starts and closes gdip:

Code: Select all

pToken := Gdip_Startup()
Gdip_Shutdown(pToken)
A lot of loading pictures:

Code: Select all

Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
Gdip_BitmapFromHWND(hwnd)
Gdip_BitmapFromScreen(Screen=0, Raster="")
Gdip_CreateBitmapFromClipboard()
...
Drawing things:

Code: Select all

Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
.
.
.
AutoHotkey itself doesn't really affect gdips speed itself.
It is a lot slower when calling gdip and after leaving a function though.

When you read through the AutoHotkey lib you will find the a lot of descriptions.
I suggest that you start with these functions:

Code: Select all

Gdip_CreateBitmap(Width, Height, Format=0x26200A)
Gdip_GraphicsFromImage(pBitmap)
Gdip_BrushCreateSolid(ARGB=0xff000000)
Gdip_CreatePen(ARGB, w)
Also:

Code: Select all

; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11
; Modifed by Rseding91 using fincs 64 bit compatible Gdip library 5/1/2013
; Supports: Basic, _L ANSi, _L Unicode x86 and _L Unicode x64
;
; Updated 2/20/2014 - fixed Gdip_CreateRegion() and Gdip_GetClipRegion() on AHK Unicode x86
; Updated 5/13/2013 - fixed Gdip_SetBitmapToClipboard() on AHK Unicode x64
Recommends AHK Studio
Miguel7
Posts: 186
Joined: 08 Sep 2014, 07:06

Re: Getting started with GDI+ (the API, not the AHK script)

03 Feb 2016, 19:00

Wow, thanks for all the info on the AHK lib! I like that idea of using the lib as a reference too. I knew the C++ version used classed, but I'm good with OOP. The confusion factor comes from the pixel array stuff... But yeah, I'm definitely gonna try gdip.ahk

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 80 guests