[GDI] Write text into an image Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

[GDI] Write text into an image

18 Apr 2021, 11:10

Code: Select all

pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromFile("myImage.png")
G := Gdip_GraphicsFromImage(pBitmap)
Gdip_TextToGraphics(G, "Hello!", "x10 y10", "Arial")
Gdip_SaveBitmapToFile(pBitmap, "myOutImage.png")
Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Does someone know how to change the color of the text?
I tried

Code: Select all

Gdip_TextToGraphics(G, "Hello!", "x10 y10 cWhite", "Arial")
Also colorWhite, but still writing the text with black color.
User avatar
mikeyww
Posts: 26891
Joined: 09 Sep 2014, 18:38

Re: [GDI] Write text into an image

18 Apr 2021, 11:27

I have not tested, but try:

Code: Select all

Gdip_TextToGraphics(G, "Hello!", "x10 y10 CFFFFFF", "Arial")
c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: [GDI] Write text into an image

18 Apr 2021, 11:35

mikeyww wrote:
18 Apr 2021, 11:27
I have not tested, but try:

Code: Select all

Gdip_TextToGraphics(G, "Hello!", "x10 y10 CFFFFFF", "Arial")
With CFFFFFF it does not write anything

The doc I got doesn't help much:

Code: Select all

Gdip_TextToGraphics(pGraphics, Text, Options, Font:="Arial", Width:="", Height:="", Measure:=0, userBrush:=0, Unit:=0) { ;gdi
; Font parameter can be a name of an already installed font or it can point to a font file
; to be loaded and used to draw the string.
;
; Set Unit to 3 [Pts] to have the texts rendered at the same size
; with the texts rendered in GUIs with -DPIscale
;
; userBrush - if a pBrush object is passed, this will be used to draw the text
; Remarks: by changing the alignment, the text will be rendered at a different X
; coordinate position; the position of the text is set relative to
; the given X position coordinate and the text width..
; See also Gdip_SetStringFormatAlign().
;
; On success, the function returns a string in the following format:
; "x|y|width|height|chars|lines"
; The first four elements represent the boundaries of the text.
; The string is returned by Gdip_MeasureString()
I could see that it uses some regex to match the options

Code: Select all

   Static Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout", Alignments := "Near|Left|Centre|Center|Far|Right" ;gdi

   IWidth := Width, IHeight:= Height ;gdi
   pattern_opts := (A_AhkVersion < "2") ? "iO)" : "i)" ;gdi
   RegExMatch(Options, pattern_opts "X([\-\d\.]+)(p*)", xpos) ;gdi
   RegExMatch(Options, pattern_opts "Y([\-\d\.]+)(p*)", ypos) ;gdi
   RegExMatch(Options, pattern_opts "W([\-\d\.]+)(p*)", Width) ;gdi
   RegExMatch(Options, pattern_opts "H([\-\d\.]+)(p*)", Height) ;gdi
   RegExMatch(Options, pattern_opts "C(?!(entre|enter))([a-f\d]+)", Colour) ;gdi
   RegExMatch(Options, pattern_opts "Top|Up|Bottom|Down|vCentre|vCenter", vPos) ;gdi
   RegExMatch(Options, pattern_opts "NoWrap", NoWrap) ;gdi
   RegExMatch(Options, pattern_opts "R(\d)", Rendering) ;gdi
   RegExMatch(Options, pattern_opts "S(\d+)(p*)", Size) ;gdi
sanmaodo
Posts: 45
Joined: 28 Aug 2020, 01:39

Re: [GDI] Write text into an image  Topic is solved

18 Apr 2021, 11:57

FF [transparency] FFFFFF [colour]

Code: Select all

Gdip_TextToGraphics(G, "Hello!", "x10 y10 CFFFFFFFF", "Arial")

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333 and 280 guests