troubleshooting Question

Increase image resolution in C#

Avatar of tradeinfo
tradeinfoFlag for United States of America asked on
C#.NET ProgrammingImages and Photos
3 Comments2 Solutions1095 ViewsLast Modified:
I use this code to create an image in C#.  It is a rectangle with a number inside.  What is the best way to increase this image's resolution.  I add this image to another image and it looks blurry.

int imageSize = 30;

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imageSize, imageSize);

using (Graphics g = Graphics.FromImage(bitmap))
    SolidBrush redSolidBrush = new SolidBrush(System.Drawing.Color.DarkViolet);
    g.FillRectangle(redSolidBrush, 0, 0, imageSize, imageSize - 5);

    Font drawFont = new Font("Ariel Black", 12, System.Drawing.FontStyle.Regular);
    SolidBrush whiteSolidBrush = new SolidBrush(System.Drawing.Color.White);

    string label = "100";
    SizeF stringSize = g.MeasureString(label, drawFont);

    float startX = (imageSize - stringSize.Width) / 2;
    float startY = (imageSize - stringSize.Height) / 2 - 2.5f;

    g.DrawString(label, drawFont, whiteSolidBrush, new PointF(startX, startY));

    System.IO.Stream imageStream = new System.IO.MemoryStream();
    bitmap.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
Russ SuterSenior Software Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros