Burgs Posted January 2, 2018 Share Posted January 2, 2018 (edited) Hello, I'm using code as below to 'draw' text strings within an image. It generally works fine, however I'm seeing a 'bug' with a certain image I use as a background. For some reason the text will not be created in that one particular image...even when it works in other images with similar sizes. I believe the problem MIGHT be that I'm not setting the width and height dimensions in the '_GDIPlus_RectFCreate' command (the last 2 optional parameters). expandcollapse popupGlobal $_Line1_SETS[5] = [-1, -1, -1, -1, -1] $a_font = _ChooseFont() if @error <> 0 Then MsgBox(4096, "", "No File(s) chosen") Else $_Line1_SETS[0] = $a_font[2] $_Line1_SETS[1] = $a_font[3] $_Line1_SETS[2] = $a_font[4] $_Line1_SETS[3] = $a_font[7] $_Line1_SETS[4] = $a_font[1] EndIf ;@error set when accessing 'font dialog'...OR NOT... $hImage = _GDIPlus_ImageLoadFromFile(@MyDocuments & "\sample.jpg") ;load an image file... $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) ;create Graphics object... $_icon_x = 487 $_icon_y = 278 $_FONT_STR = "Hello World" $_FONT_FONT = $_Line1_SETS[0] $_FONT_SIZE = $_Line1_SETS[1] $_FONT_COLOR = $_Line1_SETS[3] $_FONT_ADJ = $_Line1_SETS[4] $_FONT_VERTS = _GDIPlus_StringFormatCreate() ;draws horizontally within the image $hFamily = _GDIPlus_FontFamilyCreate(String($_FONT_FONT)) ;control 'FONT' used here... $hFont = _GDIPlus_FontCreate($hFamily, $_FONT_SIZE, $_FONT_ADJ) ;control 'FONT SIZE' here... $tLayout = _GDIPlus_RectFCreate($_icon_x, $_icon_y) ;control X, Y placement here... $hFormat = $_FONT_VERTS $hBrush2 = _GDIPlus_BrushCreateSolid(0xC4FF0000) ;creates a solid brush with specified color used to $hPen = _GDIPlus_PenCreate(0xC4000000, 1) ;create a pen with specified color and size dimensions $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, String($_FONT_STR), $hFont, $tLayout, $hFormat) $iWidth = DllStructGetData($aInfo[0], "Width") $iHeight = DllStructGetData($aInfo[0], "Height") _GDIPlus_GraphicsDrawStringEx($hGraphic, String($_FONT_STR), $hFont, $aInfo[0], $hFormat, $hBrush2) The reason I believe the '_GDIPlus_RectFCreate' is causing a problem is because my variables for '$iWidth' and '$iHeight' are reporting very small values, like less than "1"...for the one image i'm having a problem with. With other images (which 'draw' the text without difficulty) the reported values for those variables are much higher. I'm a bit confused with how to set the rectangle width and height using the '_GDIPlus_RectFCreate' command...for example if my font size is "14" then should that be used for the 'height'...? If so what should be used for the 'width'...these values will always vary depending on the font as well... I'm not even sure this is the cause of my problem, however it is the only odd thing I can see when the text fails to draw in one particular image...I was hoping being able to set the width and height of the rectangle dimensions might solve the problem. Any advice is greatly appreciated. I thank you in advance. Regards Edited January 2, 2018 by Burgs Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now