Hmm, I don't know if the encoder can do a 1bpp. I was unaware that it did
8bpp. Maybe this is what it does if the original image has a palette. I
All new articles provide code in C# and VB.NET.
"sklett" <s@s.com> wrote in message
news:ureIjHyeIHA.2448@TK2MSFTNGP03.phx.gbl...
> Hi Bob,
>
> Thanks for the reply.
> According to Photoshop, the png it saves is a 1BBP and the one gdi+ saved
> is an 8BPP.
> You are the guru, so I'm not taking photoshop's word for it just yet.
> ;0)
>
> Is it possible that gdi+ could be saving the png as a 8bpp? Is there a
> definitive way to determine the bit depth?
>
> Thanks,
> Steve
>
> "Bob Powell [MVP]" <bob@spamkillerbobpowell.net> wrote in message
> news:0E41804B-5E45-4C0B-9DFB-036D23647DF3@microsoft.com...
>> It's possible that photoshop is saving the file in an 8 bit palettised
>> mode with an optimised colour palette. GDI+ will always save as a 32bit
>> per pixel (3*8bits +8 bits alpha)
>>
>> Png compression is lossless so you can do nothng to change that.
>>
>> The only other option would be to use the 3.0 framework image libraries
>> that have more possibilities. See the PngBitmapEncoder.
>>
>> --
>> --
>> Bob Powell [MVP]
>> Visual C#, System.Drawing
>>
>> Ramuseco Limited .NET consulting
>>
http://www.ramuseco.com >>
>> Find great Windows Forms articles in Windows Forms Tips and Tricks
>>
http://www.bobpowell.net/tipstricks.htm >>
>> Answer those GDI+ questions with the GDI+ FAQ
>>
http://www.bobpowell.net/faqmain.htm >>
>> All new articles provide code in C# and VB.NET.
>> Subscribe to the RSS feeds provided and never miss a new article.
>>
>>
>> "sklett" <s@s.com> wrote in message
>> news:eJ5muKleIHA.4728@TK2MSFTNGP03.phx.gbl...
>>> (I posted this in the C# NG on accident, reposting here)
>>>
>>> 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
>>>
>>>
>>>
>>
>
>