如果tiff具有不同图像类型的页面,为什么ImageResizer不处理tiff页面的提取?

时间:2012-06-28 22:13:27

标签: c# imageresizer

我在控制台应用程序中使用imageresizer.net从tiff图像中提取页面,但是当tiff包含不同图像类型的页面时,imageresizer提取的内容并不总是代表原始页面。

我正在使用托管API,使用以下代码: ImageBuilder.Current.Build(sourceImagePath, destinationImagePath, new ResizeSettings("page=[whatever]"));

TIFF图片包含......

  • 第1页,图像类型"双层(白色为零)",压缩"第3组",尺寸" 485kb"。
  • 第2页,图像类型&#34; YCbCr(2,1次采样)&#34;,压缩&#34; JPEG(旧式)&#34;,尺寸&#34; 11MB&#34;。< / LI>
  • 第3页,图像类型&#34; YCbCr(2,1次采样)&#34;,压缩&#34; JPEG(旧式)&#34;,尺寸&#34; 11MB&#34;。< / LI>
  • 第4页,图像类型&#34;灰度(256灰色,黑色为零)&#34;,压缩&#34; JPEG(旧式)&#34;,尺寸&#34; 4MB&#34;

我得到的行为是......

  • 提取第1页的工作正常。
  • 提取第2页最终会提取第1页的图像。
  • 提取第3页最终会提取第1页的图像,但会压缩到图像左侧约1厘米宽的条带,其余图像会变黑。
  • 正在提取第4页。

我还使用libtiff.net使用this method提取相同的图像,但没有出现相同的错误。

编辑 - 使用此代码使用Wic解码器进行测试:

var settings = new ResizeSettings("decoder=wic&page=" + pageNumber);
Config.Current.Plugins.GetOrInstall<WicDecoderPlugin>();
ImageBuilder.Current.Build(sourceImagePath, destImagePath, settings);

这适用于第1页&amp; 4(没有更改),但是我得到的对象引用没有设置为对象的实例。&#39;第2页和第2页的错误3使用Wic解码器时。

编辑2 - 将未能进入MVC项目的位转换为/resizer.debug:

Image resizer diagnostic sheet      29/06/2012 4:08:14 a.m.

4 Issues detected:

(Warning):  To potentially see additional errors here, perform an image resize request.


(Warning):  You are running a hotfix version of the ImageResizer.
            You should upgrade to a released version with an equal or higher version number as soon as possible. Hotfix and release DLLs with the same version number are not the same - the release DLL should be used instead.
            Assemblies marked as hotfix versions: ImageResizer, ImageResizer.Mvc

(Warning):  NoCache is only for development usage, and cannot scale to production use.
            Add DiskCache or CloudFront for production use

(Warning):  Potentially incompatible ImageResizer assemblies were detected.
            Please make sure all ImageResizer assemblies are from the same version. Compatibility issues are possible if you mix plugins from different releases.
            3.2.3 assemblies: ImageResizer, ImageResizer.Mvc
            3.2.2 assemblies: ImageResizer.Plugins.Logging, ImageResizer.Plugins.Wic


You are using paid bundles: Design Bundle

Registered plugins:

ImageResizer.Plugins.Basic.DefaultEncoder
ImageResizer.Plugins.Basic.NoCache
ImageResizer.Plugins.Basic.ClientCache
ImageResizer.Plugins.Basic.Diagnostic
ImageResizer.Plugins.Basic.SizeLimiting
ImageResizer.Plugins.MvcRoutingShim.MvcRoutingShimPlugin
ImageResizer.Plugins.WicDecoder.WicDecoderPlugin
ImageResizer.Plugins.Logging.LoggingPlugin

Configuration:

<resizer>
<plugins>
<add name="MvcRoutingShim" />
<add name="WicDecoder" />
<add name="Logging" />
</plugins>
</resizer>


Accepted querystring keys:

quality, format, thumbnail, maxwidth, maxheight, width, height, w, h, scale, stretch, crop, cropxunits, cropyunits, page, bgcolor, rotate, flip, sourceFlip, sFlip, sRotate, borderWidth, borderColor, paddingWidth, paddingColor, ignoreicc, frame, useresizingpipeline, cache, process, margin, anchor, dpi, mode, zoom, 

Accepted file extensions:

bmp, gif, exif, png, tif, tiff, tff, jpg, jpeg, jpe, jif, jfif, jfi, 

Environment information:

Running Microsoft Windows NT 6.1.7601 Service Pack 1 and CLR 4.0.30319.269
Trust level: Unrestricted
OS bitness: x86 !! Warning, running as 32-bit on a 64-bit OS(AMD64). This will limit ram usage !!
Executing assembly: C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.exe
IntegratedPipeline: False

Loaded assemblies:

mscorlib                                 Assembly: 4.0.0.0         File: 4.0.30319.269   Info: 4.0.30319.269
System.Web                               Assembly: 4.0.0.0         File: 4.0.30319.272   Info: 4.0.30319.272
System                                   Assembly: 4.0.0.0         File: 4.0.30319.269   Info: 4.0.30319.269
System.Core                              Assembly: 4.0.0.0         File: 4.0.30319.233   Info: 4.0.30319.233
System.Configuration                     Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Xml                               Assembly: 4.0.0.0         File: 4.0.30319.233   Info: 4.0.30319.233
System.Runtime.Caching                   Assembly: 4.0.0.0         File: 4.0.30319.237   Info: 4.0.30319.237
Microsoft.Build.Utilities.v4.0           Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.RegularExpressions            Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
Microsoft.Build.Framework                Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Data                              Assembly: 4.0.0.0         File: 4.0.30319.237   Info: 4.0.30319.237
Microsoft.JScript                        Assembly: 10.0.0.0        File: 10.0.30319.1    Info: 10.0.30319.1
CppCodeProvider                          Assembly: 10.0.0.0        File: 10.0.30319.1    Info: 10.0.30319.1
System.Web.WebPages.Deployment           Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.WebPages                      Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.Mvc                           Assembly: 3.0.0.0         File: 3.0.20105.0    
Microsoft.Web.Infrastructure             Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.WebPages.Razor                Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.Razor                         Assembly: 1.0.0.0         File: 1.0.20105.407  
App_global.asax.ijrgfwnu                 Assembly: 0.0.0.0        
PNCC.LimDocumentBuilder.ImageResizerTest Assembly: 1.0.0.0         File: 1.0.0.0        
WebDev.WebHost40                         Assembly: 10.0.0.0        File: 10.0.40219.1    Info: 10.0.40219.1
System.Web.Mobile                        Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.ServiceModel.Activation           Assembly: 4.0.0.0         File: 4.0.30319.233   Info: 4.0.30319.233
System.ServiceModel                      Assembly: 4.0.0.0         File: 4.0.30319.233   Info: 4.0.30319.233
System.Runtime.DurableInstancing         Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
SMDiagnostics                            Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Xaml.Hosting                      Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.Extensions                    Assembly: 4.0.0.0         File: 4.0.30319.272   Info: 4.0.30319.272
Microsoft.CSharp                         Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.Services                      Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Drawing                           Assembly: 4.0.0.0         File: 4.0.30319.282   Info: 4.0.30319.282
System.EnterpriseServices                Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.IdentityModel                     Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Runtime.Serialization             Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.ServiceModel.Web                  Assembly: 4.0.0.0         File: 4.0.30319.233   Info: 4.0.30319.233
System.Activities                        Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.ServiceModel.Activities           Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.WorkflowServices                  Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Data.DataSetExtensions            Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Xml.Linq                          Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.ComponentModel.DataAnnotations    Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.DynamicData                   Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.ApplicationServices           Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
EntityFramework                          Assembly: 4.1.0.0         File: 4.1.10331.0     Info: 4.1.10331.0
ImageResizer                             Assembly: 3.2.3.766       File: 3.2.3.766       Info: 3-2-beta-3-temp-hotfix-jun-27-2012-9am  Commit: a0f4f1e
ImageResizer.Mvc                         Assembly: 3.2.3.766       File: 3.2.3.766       Info: 3-2-beta-3-temp-hotfix-jun-27-2012-9am  Commit: a0f4f1e
ImageResizer.Plugins.Logging             Assembly: 3.2.2.0         File: 3.2.2.0         Info: 3-2-beta-2  Commit: 3704dd6
ImageResizer.Plugins.Wic                 Assembly: 3.2.2.0         File: 3.2.2.0         Info: 3-2-beta-2  Commit: 3704dd6
NLog                                     Assembly: 2.0.0.0        
System.Web.Abstractions                  Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1
System.Web.Helpers                       Assembly: 1.0.0.0         File: 1.0.20105.407  
System.Web.Routing                       Assembly: 4.0.0.0         File: 4.0.30319.1     Info: 4.0.30319.1

2 个答案:

答案 0 :(得分:1)

这是我尝试继承BuilderExtension,覆盖DecodeStream和libtiff.net中的粘合。

这是我的两个测试tiff different size pages&amp; pages with different colour space。我已针对ImageBuilder v3.2.2编译。

当我使用以下代码在ImageResizer v3.2.2源中使用ConsoleApplication项目时,我遇到了错误。我目前没时间解决这个问题了,所以我想我会把我的进展放在这里以防万一其他人想要进一步解决这个问题。

我的测试代码

我认为在ImageResizer.ImageBuilder.PrepareDestinationBitmap()的{​​{1}}处失败但参数无效。错误。尺寸是w = 9994,h = 7102并且我怀疑这可能是内存问题 - 但是如果我首先使用s.destBitmap = ...解码tiff并将其作为内存流传递给ImageResizer,则该错误不存在。此外,v3.2.2和v3.2.3都会出现此故障。

DecodeTiffTo32BitBitmap()

我的TiffDecoder类:

var Path = @"[whatever]\TiffDecoderTests\";
var c = new Config();      
new TiffDecoder().Install(c);      
c.BuildImage(Path + "different_page_sizes.TIF", Path + "different_page_sizes-page2-TiffReader.png", "format=png&page=2&decoder=tiffdecoder");   

答案 1 :(得分:0)

2012年12月12日更新:

FreeImageDecoder插件现在支持多页TIFF文件,并在内部使用libtiff。这是处理非常复杂/罕见的.TIFF文件的建议方法。


TIFF格式非常复杂且标准化程度很低。大多数库(如GDI +(System.Drawing)和WIC(WPF))只实现标准的一小部分,更不用说事实上的功能和添加。

要获得此级别的.TIFF支持,您需要使用库专用到.TIFF支持,例如libtifflibtiff.net

ImageResizer 通过FreeImage和FreeImageDecoder插件与LibTiff集成,但尚未实现多页支持

没有划桨你不是一条小溪 - 有很多方法可以解决你的困境:

  1. Fork FreeImageDecoder并添加多页支持。难度:7
  2. 子类BuilderExtension,覆盖DecodeStream,并在libtiff.net中粘合。难度:5
  3. Subclass BuilderExtension,覆盖DecodeStream,并在libtiff中粘合。难度:10
  4. Post your idea on the UserVoice site and get 30 votes。困难:<?/ LI>
  5. Pay me to do it。难度:3(我的下一个可用时段是从现在开始的几个月)。
  6. 已经有4个解码器的示例实现:ImageBuilder.DecodeStream,PsdReader,WicDecoder,FreeImageDeocoder和PdfRenderer。他们的源代码is included in the download。平均解码器需要不到80行代码。