Solved

C# wants to save Bitmap to High resolution

Posted on 2008-10-13
5
3,047 Views
Last Modified: 2013-12-17
HEllo All,
   I need a help to save drawn image to some good resolution.

I am drawing My project related Graphs on C# Form using Drawline,drawsrtring etc.....
Up to hee it wwas fine. i am able to see the drawn image on Form with good resolution.

Now i need to save this "Graph image: to .jpeg format.when i am saving this the resolution is very low on the saved file.how can i overcome this problem? is there any solution to increase the Resolution of the image before saving.

Please help.....

code sample which i am using to save the image to file is

ImageFormat format = ImageFormat.JPEG  ;
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = JPEGFiles(*.jpg)|*.jpg";
            if (sfd.ShowDialog() == DialogResult.OK)
            {        // now save the image in the DrawArea    
                DrawArea.Save(sfd.FileName, format);
               
            }


image.jpg
0
Comment
Question by:SS_NN
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 22709313
Bitmap b = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(b);
b.SetResolution(img.HorizontalResolution, img.VerticalResolution);

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

b.Save(filename, ImageFormat.Jpeg);

From the example, you can see you need decide the color resolution when creating bitmap
and then resolution at two direction for graph.

try it.
0
 

Author Comment

by:SS_NN
ID: 22709697
Hi rendaduiyan,

  Thank you for your solution.but still i am not able to see good resolution one.....
battery.bmp
0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 22717898
it would be better if I can see your code.

I think it is the way you draw those strings that makes you think they are not in good resolution.

can you change the font, background and foreground color?

Or what the size of your area? what the font size?
0
 
LVL 5

Accepted Solution

by:
rendaduiyan earned 500 total points
ID: 22718263
And please try different smoothmode, say,
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
different interpolation mode, say,
grfx.InterpolationMode = InterpolationMode.HighQualityBilinear;
when initializing component,

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.ClientSize = new System.Drawing.Size(292, 273);
0
 

Author Comment

by:SS_NN
ID: 22720653
Thnkas for your solution. i was able to see the grpah with good resolution.
with the above code snippet i have increased the thickness of the line.

Thanks you verymuch for your help.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

831 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