473,324 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Text in Bitmap question:

Hi!

I'm outputing text to bitmap using following code:

//Create new bitmap
oPic = new Bitmap(100,150);

//Get Graphics
Graphics g = Graphics.FromImage(oPic);

//Set quality to high.
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.Clear(Color.White);

Font myFont = new Font("Arial", 7);
SolidBrush myBrush = new SolidBrush(Color.Black);

// Create point for upper-left corner of drawing.
float x = 0.0F;
float y = 0.0F;

// Set format of string.
StringFormat myFormat = new StringFormat();
myFormat.FormatFlags = StringFormatFlags.FitBlackBox;

// Create rectangle for drawing.
float width = 99.0F;
float height = 149.0F;
RectangleF myRect = new RectangleF( x, y, width, height);
// Draw rectangle to screen.
Pen whPen = new Pen(Color.Black);
g.DrawRectangle(whPen, x, y, width, height);

g.DrawString(s, myFont, myBrush, myRect, myFormat);
But I have following problem:

Sometimes I have more text then could fit in rectangle specified.

Ideally I would like to create bitmap with width(100) and heigth that allow
for all text to be fit.

Any ideas on how to do this?

Thanks!

Nov 15 '05 #1
3 7861
Since there is no reply I assume it's not possible...
"Ivan Demkovitch" <i@a.b> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
Hi!

I'm outputing text to bitmap using following code:

//Create new bitmap
oPic = new Bitmap(100,150);

//Get Graphics
Graphics g = Graphics.FromImage(oPic);

//Set quality to high.
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.Clear(Color.White);

Font myFont = new Font("Arial", 7);
SolidBrush myBrush = new SolidBrush(Color.Black);

// Create point for upper-left corner of drawing.
float x = 0.0F;
float y = 0.0F;

// Set format of string.
StringFormat myFormat = new StringFormat();
myFormat.FormatFlags = StringFormatFlags.FitBlackBox;

// Create rectangle for drawing.
float width = 99.0F;
float height = 149.0F;
RectangleF myRect = new RectangleF( x, y, width, height);
// Draw rectangle to screen.
Pen whPen = new Pen(Color.Black);
g.DrawRectangle(whPen, x, y, width, height);

g.DrawString(s, myFont, myBrush, myRect, myFormat);
But I have following problem:

Sometimes I have more text then could fit in rectangle specified.

Ideally I would like to create bitmap with width(100) and heigth that allow for all text to be fit.

Any ideas on how to do this?

Thanks!

Nov 15 '05 #2
Hi Ivan,

You might want to use the Graphics.MeasureString method. It will give you
size information which might help you.

Eric-Paul Jansen
Inforay International B.V. (http://www.inforay.com)
The Netherlands

"Ivan Demkovitch" <i@a.b> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...
Since there is no reply I assume it's not possible...
"Ivan Demkovitch" <i@a.b> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
Hi!

I'm outputing text to bitmap using following code:

//Create new bitmap
oPic = new Bitmap(100,150);

//Get Graphics
Graphics g = Graphics.FromImage(oPic);

//Set quality to high.
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.Clear(Color.White);

Font myFont = new Font("Arial", 7);
SolidBrush myBrush = new SolidBrush(Color.Black);

// Create point for upper-left corner of drawing.
float x = 0.0F;
float y = 0.0F;

// Set format of string.
StringFormat myFormat = new StringFormat();
myFormat.FormatFlags = StringFormatFlags.FitBlackBox;

// Create rectangle for drawing.
float width = 99.0F;
float height = 149.0F;
RectangleF myRect = new RectangleF( x, y, width, height);
// Draw rectangle to screen.
Pen whPen = new Pen(Color.Black);
g.DrawRectangle(whPen, x, y, width, height);

g.DrawString(s, myFont, myBrush, myRect, myFormat);
But I have following problem:

Sometimes I have more text then could fit in rectangle specified.

Ideally I would like to create bitmap with width(100) and heigth that

allow
for all text to be fit.

Any ideas on how to do this?

Thanks!


Nov 15 '05 #3
Eric,

Thanks, Thats what I needed.
"Eric-Paul" <@> wrote in message
news:3f*********************@news.nl.uu.net...
Hi Ivan,

You might want to use the Graphics.MeasureString method. It will give you
size information which might help you.

Eric-Paul Jansen
Inforay International B.V. (http://www.inforay.com)
The Netherlands

"Ivan Demkovitch" <i@a.b> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...
Since there is no reply I assume it's not possible...
"Ivan Demkovitch" <i@a.b> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
Hi!

I'm outputing text to bitmap using following code:

//Create new bitmap
oPic = new Bitmap(100,150);

//Get Graphics
Graphics g = Graphics.FromImage(oPic);

//Set quality to high.
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.Clear(Color.White);

Font myFont = new Font("Arial", 7);
SolidBrush myBrush = new SolidBrush(Color.Black);

// Create point for upper-left corner of drawing.
float x = 0.0F;
float y = 0.0F;

// Set format of string.
StringFormat myFormat = new StringFormat();
myFormat.FormatFlags = StringFormatFlags.FitBlackBox;

// Create rectangle for drawing.
float width = 99.0F;
float height = 149.0F;
RectangleF myRect = new RectangleF( x, y, width, height);
// Draw rectangle to screen.
Pen whPen = new Pen(Color.Black);
g.DrawRectangle(whPen, x, y, width, height);

g.DrawString(s, myFont, myBrush, myRect, myFormat);
But I have following problem:

Sometimes I have more text then could fit in rectangle specified.

Ideally I would like to create bitmap with width(100) and heigth that

allow
for all text to be fit.

Any ideas on how to do this?

Thanks!



Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Philip K | last post by:
I write software that needs to draw simple engineering drawings for factory workers to read. A standard for drawings is to be able to read the text from the bottom right corner. The GDI...
6
by: charsh | last post by:
Hi, I using the code below to draw a text in a pictureBox1. //Start--------------------------------------------------------------- private void button1_Click(object sender, System.EventArgs e)...
0
by: James Dean | last post by:
Question 1:I have my full image and i only display that when the zoom rate is 1:1......i guess i will set my default display to 1:16.....is it okay to just return a thumbnail of the entire image...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
13
by: WALDO | last post by:
I have a .Net TextBox (TextBoxBase, really) in which I am appending about 20 lines of text per second. I use the AppendText() method to accomplish this. This is a great substitute for taking the...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
8
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
6
by: \Frank\ | last post by:
I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one that, for example, comes from the clipboard with CF_BITMAP. I'm guessing that a CompatableBitmap is an array of indices...
6
by: bradyounie | last post by:
I'm writing a program that displays a user-supplied Bitmap and then writes text fields to it. These "text fields" are things that the user can move around on the image, but to render them...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.