Avatar of tradeinfo
tradeinfo
Flag for United States of America asked on

Increase image resolution in C#

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))
{
    g.Clear(System.Drawing.Color.Blue);
    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));
    bitmap.MakeTransparent(System.Drawing.Color.Blue);

    System.IO.Stream imageStream = new System.IO.MemoryStream();
    bitmap.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
}

Open in new window

C#.NET ProgrammingImages and Photos

Avatar of undefined
Last Comment
tradeinfo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Russ Suter

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Karrtik Iyer

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
tradeinfo

ASKER
it turned out to be  something else.  My image was re-scaled when I added it to another image
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck