Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

draw string in a bitmap

Posted on 2013-05-12
7
Medium Priority
?
584 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 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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 describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

722 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