473,385 Members | 2,269 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,385 software developers and data experts.

Properly Sizing a Bitmap

All,

I am trying to create a bitmap dynamically based on a selection of text. Code is below:
Expand|Select|Wrap|Line Numbers
  1. bitMapImage = new
  2.                 System.Drawing.Bitmap(90,50);
  3.  
  4.       Graphics graphicImage = Graphics.FromImage(bitMapImage);
  5.  
  6.             graphicImage.Clear(Color.White);
  7.             SolidBrush drawBrush = new SolidBrush(Color.Red);
  8.  
  9.             graphicImage.DrawString(comboStampText.Text +  DateTime.Now.ToShortDateString(),
  10.                new Font("Arial", 18, FontStyle.Regular),
  11.                drawBrush, new Point(5, 5));
  12.  
Everthing works except I am having difficulty sizing the bitmap correctly based on the length of the text. Is there a way that this can be accomplished?

Regards,

Scott
Feb 4 '09 #1
1 1228
vekipeki
229 Expert 100+
You can use System.Graphics.MeasureString(text, font) to get the size of your string for that graphics instance - but it also has a couple of things you should know before using it, check this link for an example: http://www.codeproject.com/KB/GDI-pl...urestring.aspx

There is also the System.Windows.Forms.TextRenderer class, which behaves a bit different when rendering (it uses plain GDI instead of GDI+). In some cases it is a better solution (for example, when rendering semi-transparent text to a bitmap, it does a better job with anti-aliasing).
Feb 5 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Neo Geshel | last post by:
I still have a problem displaying images from an access DB using asp.net. This showimage.aspx is for an admin site. I need to pull the correct image from the correct table, hence the two GET...
0
by: J L | last post by:
The VBHelper website has very good code for printing an image of the current form. Part of this code is a routine called GetFormImage which returns a bitmap of the form. What I do not know how to...
7
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
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...
0
by: Steve Long | last post by:
Help. I don't understand why this code isn't working. Basically, I'm grabbing a portion of a form as an image using BitBlt and using DrawImage to resize it. If I just use the image I get from...
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...
2
by: Peter Oliphant | last post by:
I want to create a new Bitmap which is a portion of an existing Bitmap. For example, if I have a Bitmap that is 100x100 in size I might want to create a new Bitmap that is equivalent to the one...
5
by: =?Utf-8?B?QVRU?= | last post by:
I have a bitmap of 100X100. On the load, the bitmap is created by a function (createimage()). On my OnPaint, I draw the image back to the screen (e.Graphics.DrawImage( bitmap, destrect)). Now,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.