Solved

DPI Conversion

Posted on 2009-07-09
2
2,409 Views
Last Modified: 2013-12-03
I have a scanned image of a document that is 366dpi

width: 3424
height: 5606

I want to convert the DPI to 300.  I have used the code attached to convert it successfully to 300.  However the physical size of the image has increased and is unacceptable for our needs.  I am looking for a way to change the dpi of a tiff/bitmap and keep the original physical size of the image.  Any ideas would be great.  I am working in C# .net.


Bitmap pages = null;
System.IO.FileStream myStream = new FileStream(strImageFile, System.IO.FileMode.Open);
 pages = (Bitmap)Image.FromStream(myStream);
 pages.SetResolution(newDPI, newDPI);
  pages.Save(outFile, info, ep);

Open in new window

0
Comment
Question by:alpacaman
2 Comments
 
LVL 15

Accepted Solution

by:
oobayly earned 125 total points
ID: 24823579
You have to work out the physical size of the original first. Then you can create a duplicate of the original with a calculated pixel size based on your new resolution
      // Determine the Physical size of the original
      SizeF physical = new SizeF(
        pages.Width / pages.HorizontalResolution,
        pages.Height / pages.VerticalResolution);
 
      // Determine the required pixel size of the new image
      float newResolution = 300;
      SizeF newPixelSize = new SizeF(
        physical.Width * newResolution,
        physical.Height * newResolution);
 
      Bitmap newImage = new Bitmap(pages, Size.Round(newPixelSize));
      newImage.SetResolution(newResolution, newResolution);

Open in new window

0
 
LVL 1

Author Closing Comment

by:alpacaman
ID: 31601668
thanks for the snippet, helped a lot
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

Suggested Solutions

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.

778 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