Re: struggling to save a tiff as a PNG and keep filesize down
- From: "sklett" <s@xxxxx>
- Date: Fri, 29 Feb 2008 12:25:50 -0800
"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote in message
news:op.t69voliw8jd0ej@xxxxxxxxxxxxxxxxxxxxxxx
On Thu, 28 Feb 2008 15:20:24 -0800, Steve K. <noway@xxxxxxxxxxx> wrote:
The only other thing I can think of is that Photoshop is doing a more
elaborate analysis of the data. PNG offers a surprisingly wide variety of
compression options, mainly because how well a particular algorithm will
compress an image depends a lot on the data in the image. Fancier PNG
compression tools (which may include Photoshop) will run multiple
compressions, using varying options, and choose the best-compressing
output.
Hi Peter,
My latest research seems to indicate that the PNG saved from PS is indeed a
1BPP even though Windows reports it's a 32BPP. I checked this by opening
the PNG back into PS and it shows the "Mode" as "Bitmap".
The exact operations that I'm performing on the source TIFF in PS are:
1) open TIFF file
2) resize image to 8.5" x 11" with interpolation mode: Nearest Neighbor
3) Change resolution to 96
4) save as PNG
The resizing is required because the "Pixel Aspect ratio" is not square
because the source TIFF resolution is 204 * 98
The .Net code to mimic what I'm doing with PS is
<code>
Image img = Bitmap.FromFile("../../NA_080129_77887111.tif");
if(img.HorizontalResolution != img.VerticalResolution)
{
const float resolution = 96F;
SizeF size = new SizeF(8.5F, 11.0F);
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>
I have created a comparison of a specific (zoomed way in) section of the two
png files
http://www.pmddirect.com/temp/gdi+%20and%20PS%20comparison%20copy.png
When I open the .net saved PNG in PS, the "Mode" is RGB Color/ 8 Bits
SO! That is a great clue, not sure how I missed this before, apologies if
I've had you barking up the wrong tree.
At this point, I would say my whole problem/challenge is getting .Net to
save a 1BPP png and I bet I would have results on par with that of PS.
I doubt that .NET does any sort of comparative compression like this, and
probably just uses some "best average case" options for its compression.
If that's the reason for the difference, then you're out of luck with
respect to using the built-in .NET PNG compression.
Other options would include implementing a PNG compressor yourself
(non-trivial, but not too hard either since the PNG org web site has links
to sample code), or use some third-party library (I know of at least one
command-line utility that will do fancier compression...you could access
the command-line utility from your .NET application to handle the
compression).
I will look into this, sounds a bit daunting but might be my only option.
But before you do all that, you really should confirm that you're
comparing apples to apples. It would be a shame to do all that work for
nothing.
Finally, another possibility: you mentioned that Photoshop doesn't resize
the image with as high quality as you're getting from .NET. It's possible
that due to the lower quality, the image Photoshop is compressing really
is much more highly compressable than the image .NET is compressing. An
interesting test would be to open the image Photoshop generates (just read
the PNG file in as an Image instance), and then resave that as a new PNG.
That way you know for sure you're compressing the same exact data
Photoshop is.
That would be another "verify apples to apples" check you could make
before pursuing alternatives to using .NET's built-in PNG functionality.
[...]
It's hard to comment precisely without having a copy of the original
bitmap and of the Photoshop-created image. But I still suspect this is
a
color depth issue.
If we can't resolve this through the NG and you would like the images I
would be happy to send to you ;0)
If you want to share the files, I recommend any of several free file
upload sites that you can use. That way you can post the link and easily
share the files with whomever thinks they might be able to help, without
any extra effort on your part and without inefficiently transmitting the
files via email.
Here are three that I think work pretty well:
http://www.filecrunch.com/
http://www.sendspace.com/
http://www.yousendit.com/
They all allow the upload of files for download by others without any
requirement to register or share email addresses (at least one makes it
look like they require an email address, but it's really optional, as with
the others).
Thanks for your continued efforts to help me!
Well, I'm always happy to speculate. I wish I had more specific
information. And sadly, just based on replies I've seen to other posts
regarding PNG questions (of which there haven't been many, granted), I
have some of the most experience with that image file format out of any of
the folks who normally reply. And that's not encouraging news for you, as
I don't really have that much experience with it. :(
Sorry. :) But I'll keep trying to help if I come up with new ideas. :)
Again, thanks for the great help! I really appreciate it. I will do some
research and try to find out if it's possible to save a 1BPP png from code.
I would rather not resort to an external application if I can avoid it.
Gotta run to a meeting, I will update this thread with any additional info I
find in a few hours.
-Steve
.
- References:
- struggling to save a tiff as a PNG and keep filesize down
- From: sklett
- Re: struggling to save a tiff as a PNG and keep filesize down
- From: Peter Duniho
- Re: struggling to save a tiff as a PNG and keep filesize down
- From: sklett
- Re: struggling to save a tiff as a PNG and keep filesize down
- From: Peter Duniho
- Re: struggling to save a tiff as a PNG and keep filesize down
- From: Steve K.
- Re: struggling to save a tiff as a PNG and keep filesize down
- From: Peter Duniho
- struggling to save a tiff as a PNG and keep filesize down
- Prev by Date: oledb and dbase III files
- Next by Date: Re: How to get events assigned to ToolStripMenuItem.Click
- Previous by thread: Re: struggling to save a tiff as a PNG and keep filesize down
- Next by thread: Re: struggling to save a tiff as a PNG and keep filesize down
- Index(es):
Relevant Pages
|