关于C# Image.SelectActiveFrame 轮询tif页,出现GDI+错误的问题(win svr 2008 r2)

andison_karas 2017-01-11 04:23:14
求大神

1、特定tif(部分资料显示可能是由jpeg压缩制成的tif页会出错)才会出现本问题
2、该tif在Exception的win svr 2008上可以被系统图片浏览器打开
3、tif本身由TiffToy等工具都可以拆分、读取
4、而同一个tif同一段代码在win svr 2003/win 2010时不会Exception,win svr 2008 r2(数台2008皆有本问题)
5、tif地址:http://pan.baidu.com/s/1nvlVytj
6、代码如下
 using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace ConsoleApplication1
{
class Program
{

static private ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}

static void Main(string[] args)
{

string str = string.Empty;
while (true)
{
if (str != string.Empty)
{
Console.WriteLine("ex 错误页" + str);
}

string sInt = Console.ReadLine();

int E = 0;

using (Image img = Image.FromFile(@"c:\test\011604372550903.tif"))
{
Guid guid = (Guid)img.FrameDimensionsList.GetValue(0);
FrameDimension dimension = new FrameDimension(guid);
ImageCodecInfo codeInfo = GetEncoder(ImageFormat.Tiff);
System.Drawing.Imaging.Encoder saveEncoder = System.Drawing.Imaging.Encoder.SaveFlag;
EncoderParameters parameters = new EncoderParameters(2);
ImageCodecInfo codeInfobmp = GetEncoder(ImageFormat.Jpeg);

int totalPage = img.GetFrameCount(dimension);
for (int i = 0; i < totalPage; i++)
{
try
{
Console.WriteLine("Strat for " + (i + 1) + " SelectActiveFrame Pre");

img.SelectActiveFrame(dimension, Convert.ToInt32(i));
}
catch (Exception e)
{
E++;
str += " " + (i + 1).ToString();
}
}
}
}
}
}
}

错误截图
执行结果显示第2、第4、第7等页无法被读取,而1、3、5、6等页是没有问题的

7、tif工具导出并没有显示第2页和第3页标签的差别
Page 2 TIFF Directory at offset 0x167f4
Subfile Type: (0 = 0x0)
Image Width: 1653 Image Length: 2334
Resolution: 200, 200 pixels/inch
Bits/Sample: 1
Compression Scheme: LZW
Photometric Interpretation: palette color (RGB from colormap)
Date & Time: "2016:09:27 15:38:35"
Image Description: "A;vwh=2480x3502;xy/w=+0+0/2480;binx=200/300,bina=1/1;crop_gray=+0+0/824x1166;crop_bina=+0+0/1653x2334"
Make: "Picture Elements, Inc."
Model: "JSE"
Samples/Pixel: 1
Rows/Strip: 59
Planar Configuration: single image plane
Color Map: (present)
Software: version=jxcrgb-test1122
Predictor: none 1 (0x1)



Page 3 TIFF Directory at offset 0x1ad32
Subfile Type: (0 = 0x0)
Image Width: 1652 Image Length: 2334
Resolution: 200, 200 pixels/inch
Bits/Sample: 1
Compression Scheme: LZW
Photometric Interpretation: palette color (RGB from colormap)
Date & Time: "2016:09:27 15:38:36"
Image Description: "A;vwh=2480x3501;xy/w=+0+0/2480;binx=200/300,bina=1/1;crop_gray=+0+0/824x1166;crop_bina=+0+0/1652x2334"
Make: "Picture Elements, Inc."
Model: "JSE"
Samples/Pixel: 1
Rows/Strip: 59
Planar Configuration: single image plane
Color Map: (present)
Software: version=jxcrgb-test1122
Predictor: none 1 (0x1)
...全文
270 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
andison_karas 2017-01-13
  • 打赏
  • 举报
回复
@Chinajiyong 不是这个哟。不过还是谢谢你 再找不到解决方案只能用libtiff做个工具给c#调了
andison_karas 2017-01-11
  • 打赏
  • 举报
回复
@closurer tiff格式默认是可以读取的,好像只是对tif中的jpeg的压缩格式有问题
闭包客 2017-01-11
  • 打赏
  • 举报
回复
我之前处理 gif 的时候也是会出错的,后来下载了一个第三方的编码器。 我不知道 .NET 类库提供的编码器是否支持你所说的格式。
andison_karas 2017-01-11
  • 打赏
  • 举报
回复

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧