使用system.drawing

问题描述 投票:0回答:3
“无法从具有索引像素格式的图像创建图形对象。”

如何编辑乘法tiff?

i写了一些东西是为了从乘法tiff文件中提取单个页面。

// Load as Bitmap using (Bitmap bmp = new Bitmap(file)) { // Get pages in bitmap int frames = bmp.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); bmp.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, tiffpage); if (bmp.PixelFormat != PixelFormat.Format1bppIndexed) { using (Bitmap bmp2 = new Bitmap(bmp.Width, bmp.Height)) { bmp2.Palette = bmp.Palette; bmp2.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution); // create graphics object for new bitmap using (Graphics g = Graphics.FromImage(bmp2)) { // copy current page into new bitmap g.DrawImageUnscaled(bmp, 0, 0); // do whatever you migth to do ... } } } }
c# winforms tiff system.drawing
3个回答
6
投票
代码段加载TIF文件,并将一页(可变tiffpage中的数字)提取到新的位图中。这不是索引,可以创建图形对象。

错误:无法从具有索引像素格式的图像创建图形对象。

...与它是乘法无关。 索引图像格式意味着它具有颜色的调色板,例如这是一个256色的图像。 1位图像(B&W)也可以算作具有2个色板。

您无法对使用调色板的图像进行操作,需要首先将它们转换为15位或更多颜色深度。


1
投票
here是指GodeProject示例的链接,该示例包括用于将TIFF文件转换为普通位图的代码,然后您可以像其他任何位图一样使用它:

http://www.codeproject.com/kb/gdi-plus/bitonalimageconverter.aspx

i曾经写过很少的实用程序来从TIFF图像中创建加密的PDF。这是从TIFF映像中获取页面的一件代码:

Graphics

1
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.