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. 的錯誤


#1

您好,
我們透過 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 .( , IList1 )
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 .( , IList1 )
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)


#2

@rainmaker_ho,

我已经观察到您共享的问题并请求您提供源文件,以便在您的最终重现该问题。


#3

您好,
不好意思,檔案客戶無法提供給我們。
不知是否能避掉那個錯誤,讓我們順利存檔呢?
我會再溝通看看,是否能拿到 tiff 檔案。
週末愉快。謝謝您。


#4

@rainmaker_ho,

谢谢你的帮助。我们在等你的回复。


#5

您好,
我們發現,如果那個 Tiff 檔是沒有壓縮的話,在 Image.Load 時,就會發生錯誤。


#6

@rainmaker_ho,

您能否確認您的問題是否已解決,或者您是否仍需要有關您的問題的支持。