Image Quality ... How to improve it?

S

shapper

Hello,

I am converting PDF files pages to PNG images.

I can control the DPI of the obtained image ...
With 96 DPI I am getting an image with around 780px.
I need the image to be 900px width.

I am using the following to scale the image:

public static Bitmap Scale(Bitmap image, Double ratio) {
return Scale(image, ratio, InterpolationMode.High);
} // Scale

public static Bitmap Scale(Bitmap image, Double ratio,
InterpolationMode mode) {
Bitmap scaled = new Bitmap((Int32)(image.Width * ratio), (Int32)
(image.Height * ratio));
using (Graphics graphics = Graphics.FromImage(scaled)) {
graphics.InterpolationMode = mode;
graphics.DrawImage(image, new Rectangle(0, 0, scaled.Width,
scaled.Height), new Rectangle(0, 0, image.Width, image.Height),
GraphicsUnit.Pixel);
}
return scaled;
} // Scale

So I scaled it but the letters seems a little bit fuzzy ... not much
but still.

I am using InterpolationMode.High ... I know that if I use
InterpolationMode.Bicubic it will take a little bit more time but I
don't think this is an issues since I am doing this only once when the
file is uploaded or updated.

With 192DPI they get to big: 142KB ... I am serving around 5 images on
a page.

Maybe I should go for 120DPI and Bicubic interpolation.

Should I change some setup on my scaling?

Should I use Image Magick?

Any suggestion to find a configuration that allows me to scale the
image to 900px and have a good quality and not a really big file is
welcome.

Thanks,
Miguel
 
P

Peter Duniho

shapper said:
Hello,

I am converting PDF files pages to PNG images.

I can control the DPI of the obtained image ...

How? You haven't explained anything about where these images comes
from, or what degree of control you have over them.
With 96 DPI I am getting an image with around 780px.

Which works out to an image 8.125" in width.
I need the image to be 900px width.

Why not just render the image at the appropriate DPI for that size? In
this case, 8.125" at 110.8 DPI gets you 900 pixels. More generally,
just calculate the target DPI as 900 divided by the image width in inches.

If you cannot control the DPI to that precision, then you could for
example get the image at 111 DPI. That gets you 902 pixels.

If the image has to be _exactly_ 900 pixels wide, and you can't specify
the DPI to the nearest tenth, but you can specify it to the nearest
integer, then you should be able to get good results by simply cropping
the result. You'll lose a pixel or two, but it's likely no one would
notice that and the results should be the best quality possible.

If none of that is practical, then you will either have to just accept
the loss of image quality scaling an image to one almost the same size
but not exactly, or you'll have to start with a much larger image and
scale it down (giving the scaling algorithm more data to work with will
result in a better quality result).

Your only objection to the size of the image seems to be with respect to
bandwidth concerns, but if you scale the image before transmitting it,
this shouldn't be an issue at all.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top