S
sklett
I have a Tiff (fax) with the following properties:
width: 1728
height: 1090
x resolution: 204
y resolution: 98
bit depth: 1
If I open this tiff in Photoshop and change the resolution to 96 and resize
to 816 x 1056, then save as png the size is 3.1Kb (great!)
If I resize the tiff with gdi+ and save as png (same setting as Photoshop)
the filesize is 31Kb (bad!!!)
Here is the code I'm using to resize and save as png:
<code>
Image img = Bitmap.FromFile("../../2109790117_080129_77862164.tif");
if(img.HorizontalResolution != img.VerticalResolution)
{
const float resolution = 96F;
// get the physical dimensions of the document
SizeF size = new SizeF(img.Width / img.HorizontalResolution, img.Height
/ img.VerticalResolution);
Size pixelDimensions = new Size((int)(size.Width * resolution),
(int)(size.Height * resolution));
Bitmap newImage = new Bitmap(pixelDimensions.Width,
pixelDimensions.Height);
newImage.SetResolution(resolution, resolution);
using(Graphics g = Graphics.FromImage(newImage))
{
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.DrawImage(img, new Rectangle(0, 0, pixelDimensions.Width,
pixelDimensions.Height),
0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
}
img = newImage;
}
string fn = Guid.NewGuid().ToString() + ".png";
img.Save(fn, System.Drawing.Imaging.ImageFormat.Png);
</code>
The image quality of the resize using GDI+ is much better than Photoshops.
I'm using NearestNeighbor in both cases but the results are not the same.
If anyone can shed some light, offer some pointers, whatever I would really
appreciate it. I need to keep the filesize as small as possible.
Thanks,
Steve
width: 1728
height: 1090
x resolution: 204
y resolution: 98
bit depth: 1
If I open this tiff in Photoshop and change the resolution to 96 and resize
to 816 x 1056, then save as png the size is 3.1Kb (great!)
If I resize the tiff with gdi+ and save as png (same setting as Photoshop)
the filesize is 31Kb (bad!!!)
Here is the code I'm using to resize and save as png:
<code>
Image img = Bitmap.FromFile("../../2109790117_080129_77862164.tif");
if(img.HorizontalResolution != img.VerticalResolution)
{
const float resolution = 96F;
// get the physical dimensions of the document
SizeF size = new SizeF(img.Width / img.HorizontalResolution, img.Height
/ img.VerticalResolution);
Size pixelDimensions = new Size((int)(size.Width * resolution),
(int)(size.Height * resolution));
Bitmap newImage = new Bitmap(pixelDimensions.Width,
pixelDimensions.Height);
newImage.SetResolution(resolution, resolution);
using(Graphics g = Graphics.FromImage(newImage))
{
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.DrawImage(img, new Rectangle(0, 0, pixelDimensions.Width,
pixelDimensions.Height),
0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
}
img = newImage;
}
string fn = Guid.NewGuid().ToString() + ".png";
img.Save(fn, System.Drawing.Imaging.ImageFormat.Png);
</code>
The image quality of the resize using GDI+ is much better than Photoshops.
I'm using NearestNeighbor in both cases but the results are not the same.
If anyone can shed some light, offer some pointers, whatever I would really
appreciate it. I need to keep the filesize as small as possible.
Thanks,
Steve