Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

GDI+ standard library 1.45 by tic


  • Please log in to reply
1385 replies to this topic
Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
You can try with Gdip_All works for most
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

What is the simplest way to vertically and horizontally centre text around a given x, y coordinate using Gdip_TextToGraphics()?

 

I've played around with it on other occasions, but the only way I've been able to get it vertically centred is via using the measure parameter and then calling the function again with the appropriately altered y coordinate.

 

I.e. 

The point

AxcMxZx.png

 

What it would look like without any options

EkbaJyl.png

 

What I would like it to look like

I1nCyvI.png

 

Many thanks.



tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007

Does vCenteroption not work?



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

I will have another go tonight and post the code for a basic example. 

 

The centre option works, but the vCentre option doesn't (although i'm probably doing something wrong).  Should the options string  "x40 y60 centre vCentre" produce something like the final picture posted above?

 

Cheers.



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

I think i was using the function incorrectly, although the tutorial states:

 

If either is missed (as I have missed height) then the height of the bounding box will be made to be the height of the graphics, so 100%

 

But if you do not specify a width or height, then these two variables will be null when it gets to this part of the function

	if vPos
	{
		StringSplit, ReturnRC, ReturnRC, |
		
		if (vPos = "vCentre") || (vPos = "vCenter")
			ypos += (Height-ReturnRC4)//2
		else if (vPos = "Top") || (vPos = "Up")
			ypos := 0
		else if (vPos = "Bottom") || (vPos = "Down")
			ypos := Height-ReturnRC4
		
		CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
		ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
	}

I just changed these two lines, as i'm only interested in vertical positioning of the text relative to the x, y coordinates and not the entire graphics area.

		if (vPos = "vCentre") || (vPos = "vCenter")
			ypos -= ReturnRC4//2
		else if (vPos = "Top") || (vPos = "Up")
			ypos -= ReturnRC4


bobycom
  • Members
  • 40 posts
  • Last active: Apr 14 2019 07:50 AM
  • Joined: 25 Mar 2014

Could it be possible that this library is somehow outdated? I've tried the #3 example code but it doesn't show anything at all. Yes GDI+ is installed. Yes the background.png picture is present. In fact I've tried several simular GDI+ example scripts that should draw an image in the gui. None of them work. No errors. Script running. Just no gui / picture at all.

 

The library and all the examples are working great.



serg
  • Members
  • 8 posts
  • Last active: Jul 31 2015 09:54 AM
  • Joined: 15 Feb 2012
Hi,
First, I want to say big THANK YOU to Tariq Porter for GDIP!!! It is very generous of you to put together and share all this code/tutorials.
 
For my work I need data presented visually in a very specific way, and I couldn't find solution. With GDIP lib it was easy
to achieve exactly what I needed.
Thanks Tariq, you are the man!
 
There is still one thing I'm struggling to understand, and couldn't find answer:
 
How to get Bitmap from graphics?
 
For example, I created graphics:
 
Gui, 1: +E0x80000 +LastFound +OwnDialogs -Caption
Gui, 1: Show, NA
hwnd1 := WinExist() ;Get a handle to Gui
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)

...Drew something on it... ...Updated with UpdateLayeredWindow

 
Then I need to capture only part of the image I have drawn (I will need to restore it later on screen).
From what I understand, Gdip_CloneBitmapArea can be used for that, but how do I get bitmap for my graphics?
I tried Gdip_BitmapFromHWND, but it acts strange - dims the screen for a second and doesn't get anything.
Gdip_BitmapFromScreen works, but it also captures windows that might be on top of my GUI with image.
So is there a way to get Bitmap from graphics in my example?
Any suggestions very appreciated!


tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007

Hi serg

 

I'm glad you like it. I haven't made any changes for a long time, but will look to rewrite this library in the new year for AHK_L.

 

The problem with this is that a window requires a GDI bitmap to update it, but we get all the power and general nice-ness from the GDI+ library.

So you'll notice that I create the bitmaps in different ways in the examples depending on whether I'm going to be updating to a window or not.

 

However....You shouldn't need to get back the bitmap from the graphics if you already have the bitmap and are working with it. I mean, it is possible with:

GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height, GpGraphics* target, GpBitmap** bitmap)

Which I did not include in the library as I couldn't see any use for it.
The solution to your problem really depends on your use-case. If you are not attempting to update the screen many times a second then you should do all your drawings into a GDI+ bitmap and work with that, and any time you want to update the screen then you can convert to a GDI bitmap using 

Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)

A faster method is to bitblt directly from the original GDI bitmap you have, but this adds complication if speed isn't absolutely critical.

 

Please ask if you need further clarification or help

 

Thanks



serg
  • Members
  • 8 posts
  • Last active: Jul 31 2015 09:54 AM
  • Joined: 15 Feb 2012

Tariq, thank you for prompt and detailed reply!

 

In regard to updating Gdip library - I use your old Gdip.ahk with new AHKL on Win8.1/64 and it still works fast and awesome.

 

You wrote that I can convert to GDI bitmap using 

Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)

as I understand, HBITMAP is a handle to Bitmap, but how do I get it?

 

On another solution:

GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height, GpGraphics* target, GpBitmap** bitmap)

what would be AHK equivalent? (if it is too time-consuming to translate - nevermind)

 

Speed is not critical, what Im basically trying to do is to save to memory part of the graphics that I have drawn - and later (after some modifications to original graphics) restore that original part of graphics. If there is solution which doesnt require converting to Bitmap, that will work as well.

 

In any case, really appreciate your time and effort!



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005
I wrote an easy to use library that makes examining on-screen pixels using GDI very easy.

It can be found here: http://ahkscript.org....php?f=6&t=5682

serg
  • Members
  • 8 posts
  • Last active: Jul 31 2015 09:54 AM
  • Joined: 15 Feb 2012

I wrote an easy to use library that makes examining on-screen pixels using GDI very easy.

It can be found here: http://ahkscript.org....php?f=6&t=5682

 

Gud stuff, thanks for posting!



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005
Any chance we could get a more reliable home for this library than a dropbox link?

May i suggest GitHub?

If the creators think it is a good idea, but can't be bothered, I would be happy to set one up myself.

tomoe_uehara
  • Members
  • 2166 posts
  • Last active: Jun 11 2015 05:33 PM
  • Joined: 05 Sep 2009
+1 for GitHub

bobycom
  • Members
  • 40 posts
  • Last active: Apr 14 2019 07:50 AM
  • Joined: 25 Mar 2014

Have someone tried this on Windows 7? It seems that this library is not working on my 64bit Win 7.

 

For example the function Gdip_SaveBitmapToFile is exiting with result -3 = Could not find matching encoder for specified file format. I'm testing with .jpg files.

 

Any sugestions?



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012

You can try with Gdip_All works for most


Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About