Azure 函数抛出“参数无效";在大型 TIF 文件上调用 Image.FromStream

Azure function throwing quot;parameter not validquot; calling Image.FromStream on large TIF file(Azure 函数抛出“参数无效;在大型 TIF 文件上调用 Image.FromStream)

本文介绍了Azure 函数抛出“参数无效";在大型 TIF 文件上调用 Image.FromStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Azure 函数中处理多页 TIF.该函数由 blob 存储的更改触发.当触发器运行时,它会调用:

I'm trying to process multi-page TIFs in an Azure Function. The function is triggered by changes in blob storage. When the trigger runs, it calls this:

function loadFile(Stream mpTif);
     Bitmap pageOnes = (Bitmap)Image.FromStream(mpTif);

mpTif 是直接传递到 Azure 函数的 blob 存储流.

mpTif is the blob storage Stream being passed directly into the Azure Function.

我的函数在小型多页 TIF 文件上运行良好,但是当我将一个非常大的 TIF 文件放入 blob 存储时,它在 Image.FromStream 上失败并出现错误:

My function works fine on small multi-page TIF files but when I put a very large one in the blob storage, it fails on Image.FromStream with the error:

参数无效

我正在使用本地功能主机在我自己的机器上运行它.奇怪的是,我有一个控制台应用程序,它使用完全相同的代码运行,但使用 MemoryStream 调用它:

I am running this on my own machine using the local function host. The strange thing is that I have a console application which runs using the exact same code but calls it using a MemoryStream instead:

MemoryStream data = new MemoryStream(File.ReadAllBytes("big.tif"));
loadFile(data);

这很好用.我是否在 Azure Functions 中达到某种内存限制?在我遇到那个错误之前花了很长时间,这让我觉得这是一个 OOM 的事情.此 TIF 文件非常大(80Mb 和 10,000 页).

This works fine. Am I hitting some sort of memory limit in Azure Functions? It takes suspiciously long before I hit that error, which makes me think it's an OOM thing. This TIF file is very large (80Mb and 10,000 pages).

推荐答案

我明白了 - 事实证明位图操作在运行 blob 流时一点也不开心.性能很糟糕(可能慢了 100 倍),对大文件的操作会因我上面提供的错误而失败.

I got to the bottom of this - it turns out Bitmap operations are not at all happy running off the blob Streams. The performance is terrible (perhaps 100 times slower) and operations on large files just fail with the error I provided above.

我通过使用 https://stackoverflow.com/提供的代码将传入 Stream 复制到 MemoryStream 解决了我的所有问题a/3212765/498949 在对其执行任何位图操作之前.

I resolved all of my issues by copying the incoming Stream to a MemoryStream using the code provided at https://stackoverflow.com/a/3212765/498949 before performing any Bitmap operations on it.

这篇关于Azure 函数抛出“参数无效";在大型 TIF 文件上调用 Image.FromStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Azure 函数抛出“参数无效";在大型 TIF 文件上调用 Image.FromStream

基础教程推荐