Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

C# wants to save Bitmap to High resolution

Posted on 2008-10-13
5
3,076 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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