首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bitmap.Save保持旧PixelFormat

Bitmap.Save保持旧PixelFormat
EN

Stack Overflow用户
提问于 2014-12-26 17:04:11
回答 1查看 765关注 0票数 0

我正在用下面的代码将一组TIFF图像转换为JPEG。我有一个问题,在黑白图像上,图像大小呈指数增长,上面有很多黑点。我发现进来的图像是PixelFormat Format1bppIndexed,但是它总是将它们保存为Format24bppRgb格式。有没有一种方法总是保持原始图像的PixelFormat,这样就不会出现这个问题?原始图像的PixelFormat并不总是相同的,因为图像是彩色的,b&W,灰度的。

代码语言:javascript
复制
 public static string[] ConvertTiffToJpeg(string fileName)
        {
            using (Image imageFile = Image.FromFile(fileName))
            {
                var test = imageFile.PixelFormat;

                FrameDimension frameDimensions = new FrameDimension(
                    imageFile.FrameDimensionsList[0]);

                // Gets the number of pages from the tiff image (if multipage) 
                int frameNum = imageFile.GetFrameCount(frameDimensions);
                string[] jpegPaths = new string[frameNum];

                for (int frame = 0; frame < frameNum; frame++)
                {
                    // Selects one frame at a time and save as jpeg. 
                    imageFile.SelectActiveFrame(frameDimensions, frame);
                    using (Bitmap bmp = new Bitmap(imageFile))
                    {
                        jpegPaths[frame] = String.Format("{0}\\{1}{2}.jpg",
                            Path.GetDirectoryName(fileName),
                            Path.GetFileNameWithoutExtension(fileName),
                            frame);
                        bmp.Save(jpegPaths[frame], ImageFormat.Jpeg);
                    }
                }

                return jpegPaths;
            }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-26 19:09:53

.jpg文件将是24位颜色或8位灰度.您可以使用8位灰度对1 bpp黑白tiff图像,并节省一些空间,但这是不可能使用索引的颜色或每像素1位.jpg文件。

根据图像目标应用程序的不同,您可以将1bpptiff图像保存为.png或.gif图像,而不是.jpg。如果使用索引颜色保存或用1 bpp保存的话,这应该和tiff文件一样小。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27659780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档