您好,
我們透過 Aspose.Imaging 去載入 Tiff 檔,在有些 Tiff 檔取得 TiffFrame.ImageOpacity 值時,會發生「Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.」的錯誤。
使用元件: Aspose.Imaging V 18.8.0.0 (.net 4)
測試程式如下,
var directoryPath = @"C:\projects\aspose";
var tifPath = @"err.tif";
using (var image = (TiffImage)Image.Load(Path.Combine(directoryPath, tifPath)))
{
var pngOptions = new PngOptions();
pngOptions.CompressionLevel = 9;
var i = 0;
foreach (var f in image.Frames)
{
try
{
var imageOpacity = f.ImageOpacity;
}catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
//f.Save(Path.Combine(directoryPath, $"err-{++i}.png"), pngOptions);
}
}
錯誤訊息如下,
at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
at .(Byte[] , Int32 , , , Int32 )
at .(Byte[] , Int32 )
at .(Byte[] , Int32 , Int32 )
at .(Byte[] , Int32 , Int32 )
at .(Byte[] , Int32 , Int32 )
at . (Byte[] , Int32 )
at .. (Rectangle )
at .( , IList1 ) at .(Rectangle , , , Int32 , Int32 ) at . (TiffStreamReader , Rectangle , IPartialArgb32PixelLoader ) at .LoadPartialArgb32Pixels(Rectangle , IPartialArgb32PixelLoader ) at . (Rectangle ) at .( , IList
1 )
at .(Rectangle , , , Int32 , Int32 )
at .(Rectangle , )
at .(Object )
at .(MethodBase , Boolean )
at . ( )
at .()
at .()
at .(Object )
at . ()
at . ( )
at .()
at .()
at .(Object )
at . ()
at .(Object , UInt32 )
at .()
at . ()
at .()
at .(Object )
at . ()
at .(Object , UInt32 )
at .()
at .(Object[] , Type[] , Type[] , Object[] )
at . (Rectangle , IPartialArgb32PixelLoader )
at Aspose.Imaging.RasterImage.(Rectangle , IPartialArgb32PixelLoader )
at Aspose.Imaging.RasterImage.LoadArgb32Pixels(Rectangle rectangle)
at . (Rectangle )
at .( , IList`1 )
at .(Rectangle , , , Int32 , Int32 )
at Aspose.Imaging.RasterImage.get_ImageOpacity()
大多數的檔案它的值會是 1,但如果發生這個錯誤時,呼叫 TiffFrame 去 Save 成 PNG 也會發生錯誤,訊息如下,
at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
at .(Byte[] , Int32 , , , Int32 )
at .(Byte[] , Int32 )
at .(Byte[] , Int32 , Int32 )
at .(Byte[] , Int32 , Int32 )
at .(Byte[] , Int32 , Int32 )
at . (Byte[] , Int32 )
at .. (Rectangle )
at .( , IList1 ) at .(Rectangle , , , Int32 , Int32 ) at . (TiffStreamReader , Rectangle , IPartialArgb32PixelLoader ) at .LoadPartialArgb32Pixels(Rectangle , IPartialArgb32PixelLoader ) at . (Rectangle ) at .( , IList
1 )
at .(Rectangle , , , Int32 , Int32 )
at .(Rectangle , )
at .(Object )
at .(MethodBase , Boolean )
at . ( )
at .()
at .()
at .(Object )
at . ()
at . ( )
at .()
at .()
at .(Object )
at . ()
at .(Object , UInt32 )
at .()
at . ()
at .()
at .(Object )
at . ()
at .(Object , UInt32 )
at .()
at .(Object[] , Type[] , Type[] , Object[] )
at . (Rectangle , IPartialArgb32PixelLoader )
at Aspose.Imaging.RasterImage.(Rectangle , IPartialArgb32PixelLoader )
at Aspose.Imaging.RasterImage.LoadPartialArgb32Pixels(Rectangle desiredRectangle, IPartialArgb32PixelLoader pixelLoader)
at .( , RasterImage , , Rectangle , Boolean )
at .(Stream , RasterImage , PngOptions , Rectangle , Boolean , String )
at .Export(Image , Stream , ImageOptionsBase , Rectangle )
at Aspose.Imaging.Image.Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)