Tag: pixelformat

图像resize导致文件大小比原始C#大

我一直在使用这种方法将上传的.JPG图像调整到最大宽度,但这导致图像的kb大于源。 我究竟做错了什么? 保存新图像时还需要做些什么吗? 我尝试了各种PixelFormat组合,例如PixelFormat.Format16bppRgb555 例如:源图像​​是.JPG 1900w,试图调整到1200w …… – 源文件是563KB, – 已resize的文件为926KB或更大,甚至1.9MB public static void ResizeToMaxWidth(string fileName, int maxWidth) { Image image = Image.FromFile(fileName); if (image.Width > maxWidth) { double ratio = ((double)image.Width / (double)image.Height); int newHeight = (int)Math.Round(Double.Parse((maxWidth / ratio).ToString())); Bitmap resizedImage = new Bitmap(maxWidth, newHeight); Graphics graphics = Graphics.FromImage(resizedImage); graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; graphics.CompositingQuality = […]

检查图像是否有颜色

我想弄清楚图像是否有颜色。 在这个 StackOverflow问题上,有一个回复说我应该检查Image的PixelFormat枚举。 不幸的是,回复对我来说不是很清楚。 检查image.PixelFormat是否与PixelFormat.Format16bppGrayScale不同,是否可以安全地认为它是彩色图像? 枚举的其他值怎么样? MSDN文档不是很清楚……

C#为什么Bitmap.Save会忽略Bitmap的PixelFormat?

我需要处理并保存原始bpp中的图像(1 – 对于BnW,8 – 对于灰色,24 – 颜色)。 处理后我总是有24bpp(由于使用Aforge.Net处理)。 我将原始bpp传递给保存function,我正在使用下一个代码进行保存: private static Bitmap changePixelFormat(Bitmap input, PixelFormat format) { Bitmap retval = new Bitmap(input.Width, input.Height, format); retval.SetResolution(input.HorizontalResolution, input.VerticalResolution); Graphics g = Graphics.FromImage(retval); g.DrawImage(input, 0, 0); g.Dispose(); return retval; } 当我通过时: PixelFormat.Format8bppIndexed 我得到一个例外:“图形对象无法以索引像素格式创建图像”: Graphics g = Graphics.FromImage(retval); 我试过下一个代码: Bitmap s = new Bitmap(“gray.jpg”); Bitmap NewPicture = s.Clone(new Rectangle(0, […]