Solved

draw string in a bitmap

Posted on 2013-05-12
7
581 Views
Last Modified: 2013-05-14
hi, i have this code:

    objBmpImage = New Bitmap(objBmpImage, New Size(960, 832))
    objGraphics = Graphics.FromImage(objBmpImage)
    objGraphics.SmoothingMode = SmoothingMode.AntiAlias
    objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias
    objGraphics.DrawString(vtext, New Font("Arial", 35, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel), Brushes.White, 30, 25)


how can i draw this string inside my working area of the bitmap, so if the string is small, then the size will be bigger to fill the space, if the string is bigger then the size  it will be small. and how to justify the text.
0
Comment
Question by:rafaelrgl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39159837
Try something like this:
        Dim margin As Integer = 30
        objBmpImage = New Bitmap(objBmpImage, New Size(960, 832))
        Using objGraphics As Graphics = Graphics.FromImage(objBmpImage)
            objGraphics.SmoothingMode = SmoothingMode.AntiAlias
            objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias

            Dim fSize As Integer = 7
            Dim F As Font = Nothing
            Do
                fSize = fSize + 1
                If Not IsNothing(F) Then
                    F.Dispose()
                End If
                F = New Font("Arial", fSize, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel)
            Loop While objGraphics.MeasureString(vtext, F).Width < objBmpImage.Width - (2 * margin)
            objGraphics.DrawString(vtext, F, Brushes.White, margin, 25)
            F.Dispose()
        End Using

Open in new window


It simply increases the size of the font until it no longer fits in the desired space.
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 39159972
hi idle_mind,

i´m sorry but i put the wrong line for the string, the right one is this one:

objGraphics.DrawString(vtext, New Font("Arial", 80, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel), Brushes.White, System.Drawing.RectangleF.FromLTRB(10, 120, 950, 810))

because the one i put before it~s just for one line, and i want to fit not only on the line but the text goes all the way to the end of the image, so i have an rectangleF, i need to scale to fit on this rectangle.

any help
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39159979
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Author Comment

by:rafaelrgl
ID: 39159995
emoreau,

this is not what i want, because i am doing inside an rectangleF, and not just one line so the thext goes inside a box, and i want to scale the font to fit this box, so, if i have long text, the font will be set smaller to fit the area i am printing the text, if the text is short the font will be bigger so it will fit this area.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39160002
Is the text supposed to wrap?...or does it have distinct lines that must stay on those lines and you want to maximize how those lines fit in the box?
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 39160005
it's suppose to wrap
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 39160007
and be justify
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question