为什么PngBitmapEncoder类让我的图像颗粒感看? [英] Why does the PngBitmapEncoder class make my images look grainy?
问题描述
我使用此代码的JPG图像转换成PNG 8
的代码的作品,但图像看起来颗粒感。我确实在Photoshop中导出为PNG 8,它看起来光滑,无颗粒
注意:8位PNG
任何影像大师在那里,可以帮助
我的代码:
图像镜像文件= Image.FromFile(@C:\Documents和Settings\dvela\My Documents\Downloads\pngtest\Batman01 .JPG);
矩形NewSize =新的Rectangle();
NewSize.Width = 112;
NewSize.Height =(NewSize.Width * ImageFile.Height)/ ImageFile.Width;
位图图像=新位图(NewSize.Width,NewSize.Height);
显卡显卡= Graphics.FromImage(图像);
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(镜像文件,NewSize);
FormatConvertedBitmap FCB =新FormatConvertedBitmap(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(image.GetHbitmap(),IntPtr.Zero,Int32Rect.Empty,BitmapSizeOptions.FromWidthAndHeight(NewSize.Width,NewSize.Height) ),PixelFormats.Indexed8,BitmapPalettes.Halftone256Transparent,0.5);
PngBitmapEncoder pngBitmapEncoder =新PngBitmapEncoder();
pngBitmapEncoder.Interlace = PngInterlaceOption.Off;
pngBitmapEncoder.Frames.Add(BitmapFrame.Create(FCB));使用(流FILESTREAM = File.Open(@
C:\Documents和Settings\dvela\My Documents\Downloads\pngtest\test.png,FileMode.Create) )
{
pngBitmapEncoder.Save(FILESTREAM);
}
我发现这个库,做调色板和基于八叉树颜色量化。
http://www.waterwijkers.nl/bip
这篇文章有一个伟大的演示应用程序,显示你如何使用它。
HTTP: //www.aspfree.com/c/a/C-Sharp/Lossless-Image-Resizing-in-C-Sharp/2/
这MSDN文章解释了代码算法之间的差异。
http://msdn.microsoft.com/en-us/library /aa479306.aspx
I'm using this code to convert a jpg image into a png 8. The code works but the image looks grainy. I did an export in Photoshop as png 8 and it looks smoother and no grain.
Note: 8-bit png
Any image gurus out there that can help?
My code:
Image ImageFile = Image.FromFile(@"C:\Documents and Settings\dvela\My Documents\Downloads\pngtest\Batman01.jpg");
Rectangle NewSize = new Rectangle();
NewSize.Width = 112;
NewSize.Height = (NewSize.Width * ImageFile.Height) / ImageFile.Width;
Bitmap image = new Bitmap(NewSize.Width, NewSize.Height);
Graphics graphics = Graphics.FromImage(image);
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(ImageFile, NewSize);
FormatConvertedBitmap fcb = new FormatConvertedBitmap(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(image.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(NewSize.Width, NewSize.Height)), PixelFormats.Indexed8, BitmapPalettes.Halftone256Transparent, 0.5);
PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();
pngBitmapEncoder.Interlace = PngInterlaceOption.Off;
pngBitmapEncoder.Frames.Add(BitmapFrame.Create(fcb));
using (Stream fileStream = File.Open(@"C:\Documents and Settings\dvela\My Documents\Downloads\pngtest\test.png", FileMode.Create))
{
pngBitmapEncoder.Save(fileStream);
}
I found this library that does Palette-based and Octree-based color Quantization. http://www.waterwijkers.nl/bip
This article has a great demo app that shows you how to use it. http://www.aspfree.com/c/a/C-Sharp/Lossless-Image-Resizing-in-C-Sharp/2/
This MSDN article explains the difference between the algorithms with code. http://msdn.microsoft.com/en-us/library/aa479306.aspx
这篇关于为什么PngBitmapEncoder类让我的图像颗粒感看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!