Jump to content

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

TextToImage 1.07 - Write text onto an image or screenshot


  • Please log in to reply
64 replies to this topic
tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007
The Ram is still accumulating over many passes. Have I accidentally deleted something that I can't see or what is going wrong?

This is a version of the function that returns the handle and is updating scrolling text on an alpha blended gui.

<!-- m -->https://ahknet.autoh...c/Skin Test.zip<!-- m -->

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Obviously, since the function generates a bitmap each time it is called, you must also delete a bitmap each time.

To do this, you'll need to return both bitmap handles (hBM and oBM) as well as the device context handle (mDC) so you can reselect oBM in order to delete hBM and mDC.

It would be better to maintain one bitmap and device context, and draw the text onto it rather than creating a new bitmap and device context each time. TextToImage could accept a device context handle as the output parameter, allowing you to recycle the device context returned by the previous call.

To optimize further, you could accept a bitmap handle as the input parameter, so you can load the background image from disk only once, and use it each time.

bmcclure
  • Members
  • 774 posts
  • Last active: Jan 04 2014 10:44 PM
  • Joined: 24 Nov 2007
Quality=3 fixed it. Now it is non-smoothed and it looks a lot better in my GUI.

Edit Actually, I'm still having trouble with transparency. I can see whatever's behind the picture where the text is supposed to be in my GUI. For my rollover buttons, it's the light-blue color that normally shades a button when you hover your mouse over it (in Vista with the Aero theme), which is showing through where my text is supposed to be. But it's a BMP, and I didn't have any transparency. Could this have to do with the palette of the source image?

Now for one more question (obviously much less important):

Is there any way to decrease the size of the final image? My source bitmap is 3 KB, and with the added text it becomes almost 9 KB. It's not a huge deal, I mean, what's a 6 KB difference for a button in the scheme of a GUI window going to affect, but if optimization is possible, that would be ideal.

bmcclure
  • Members
  • 774 posts
  • Last active: Jan 04 2014 10:44 PM
  • Joined: 24 Nov 2007
Any ideas about the image transparency? I can't figure out how to get the text to actually show up on my images in the color I specify... no matter what color it is, the text comes out transparent showing what is beneath it.

Could this have something to do with the source image? I'm stumped...

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
GDI does not support alpha blending. The majority of GDI rendering functions clear the alpha data of whatever pixels they affect. There are only two solutions that I know of:
[*:35zwpd7u]Render the text into a temporary bitmap and manually calculate the alpha data. Then, use Msimg32\AlphaBlend to render the temporary bitmap onto the destination bitmap.
[*:35zwpd7u]Use GDI+. Given that TextToImage already uses GDI+ to load and save images, it seems appropriate to also use GDI+ to render the text.

bmcclure
  • Members
  • 774 posts
  • Last active: Jan 04 2014 10:44 PM
  • Joined: 24 Nov 2007
But I don't want transparency on my generated buttons... not right now at least. It's being used on the text unintentionally.

The regular button text is white, and the rollover text is gold, and both are showing transparent in my GUI (eg you can see what is behind the text on the buttons). I'm not sure how this is happening.

It does seem appropriate for GDI+ to render the text, not to mention I'm using GDI+ in the same functions in my script as this anyway. Would it be simple to translate the GDI calls to GDI+ calls? If you could point me in the direction of the proper GDI+ function(s) to use, I'd be happy to have a go at it. Thanks.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Do the source images have an alpha channel? If so, rendering onto them with GDI will not work correctly. Have you tried a 24-bit bitmap, or any other format which is incapable of transparency?

MSDN: GDI+ Flat API might be of some help. Specifically:
Text Functions, see DrawString/GdipDrawString.
Graphics Functions, see GetHDC/GdipGetDC and ReleaseHDC/GdipReleaseDC. Use these to bitblt the screen/window.

One other necessary function doesn't seem to be mentioned on those pages:

GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage *image, GpGraphics **graphics);
This allows you to get a Graphics object for drawing on the GDI+ bitmap.



bmcclure
  • Members
  • 774 posts
  • Last active: Jan 04 2014 10:44 PM
  • Joined: 24 Nov 2007
I've tried using the source image as:
8-bit BMP
24-bit BMP
24-bit PNG

They all seem to render the same in my GUI. Which certainly seems odd since there shouldn't be any transparency, heh.

This is the latest source image I'm using with this function to create the buttons (a PNG):
Posted Image

tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007
i dont really understand what you mean. could you provide a screenshot with the undesireable result.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Which version of TTI are you using?

I tried the 1.07 example script with your button image, and it seemed to work fine. The generated image looks right in an image viewer and on an AutoHotkey GUI... in a picture control; how are you using the image?

In addition to a screenshot, post the code you are using to call TTI. :)

bmcclure
  • Members
  • 774 posts
  • Last active: Jan 04 2014 10:44 PM
  • Joined: 24 Nov 2007
I'm using the generated image with the AddGraphicButton() script.

I'm loading the image into the script before I use it with:
LoadImage_AGB(ByRef VariableName, ImgPath, bHeight=32, bWidth=32) {
Global
Local ImgType, ImgType1, LR_LOADFROMFILE, NULL
Static LR_LOADFROMFILE := 16
Static NULL
SplitPath, ImgPath,,, ImgType1
ImgType := (ImgType1 = "bmp") ? 0 : 1
If (VariableName != "")
  DllCall("DeleteObject", "UInt", VariableName)
VariableName := ImgType . "." . DllCall("LoadImage", "UInt", NULL, "Str", ImgPath, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt", LR_LOADFROMFILE, "UInt")
Return ErrorLevel
}

The problem is, I can see the actual Vista button underneath instead of the white or gold text. You can still read the text, but it shows up like this:
Posted Image
Note, the text looks white, but that's just because of the light-colored Vista button. When you hover over it (as shown in the left button) you can see that the button underneath is showing through, rather than the text being white then turning gold. When you move the mouse off the button, the blue fades out, just like a Vista button.

To clarify, the image looks fine when I open it in an image editor, the transparency problem only happens when I put it on my GUI like this. It does not do this if I write the exact same text on the exact same button graphic manually in Fireworks, save it, and use it in the GUI. The button looks the same in the image editor as the generated image, but only the generated one has the transparency issue.

tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007
Why use that function? Why not just gui add picture?

give me a few days. ill update the function and release the update including more examples.

bmcclure
  • Members
  • 774 posts
  • Last active: Jan 04 2014 10:44 PM
  • Joined: 24 Nov 2007
I just haven't taken the time to convert my button and rollover functions into gui pictures rather than using the AddGRaphicButton() function which I built my button code around.

But shouldn't the generated image work correctly anyway? I have no trouble with manually created images.

Not to mention several posts back in this forum I tested GUi, Add, Picture with the generated buttons and had the exact same issue--unless something has been done since then that would resolve one and not the other.

Looking forward to the new release. Thanks.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Posted Image

From top to bottom:
[*:1kwxazi5]AddGraphicButton + generated.bmp
[*:1kwxazi5]AddGraphicButton (modified to accept bitmap handle) + generated.bmp loaded with GDI+
[*:1kwxazi5]Gui,Add,Picture,, generated.bmp
[*:1kwxazi5]Gui,Add,Picture,, generated.png

bmcclure
  • Members
  • 774 posts
  • Last active: Jan 04 2014 10:44 PM
  • Joined: 24 Nov 2007
Hey can you show me the code you used for example 2? It looks like that would resolve my issue (if the text is supposed to be purple in your example that is :) )

Thanks for the help!

Update: I think the difference is I'm loading the image with that LoadImage_AGB function above, which I believe uses GDI. Would loading it with GDI+ make it appear like your second example there?

Update 2: Is there any way to pre-load an image with GDI+ and then display it with Gui, Add, Picture? I want to pre-load my rollover buttons so they aren't loaded from disk each time, and that's my only hold-up in switching from the AddGraphicButton() function to Gui, Add, Picture now.