gpt4 book ai didi

azure - 使用 DrawImage 的代码可以在本地运行,但在 Azure 中失败并出现 ArgumentException

转载 作者:行者123 更新时间:2023-12-03 00:16:32 24 4
gpt4 key购买 nike

我从我的源代码中提取了与此相关的以下代码:

using (Bitmap spriteBitmap = new Bitmap(Width, Height, PixelFormat.Format32bppArgb))
{
using (Graphics spriteGraphics = Graphics.FromImage(spriteBitmap))
{
Rectangle imageRect = new Rectangle(0, 0, imageInfo.Width, imageInfo.Height);

using (Bitmap clonedImageBitmap = imageInfo.ImageBitmap.Clone(imageRect, spriteBitmap.PixelFormat))
{
clonedImageBitmap.SetResolution(spriteBitmap.HorizontalResolution, spriteBitmap.VerticalResolution);

spriteGraphics.DrawImage(
clonedImageBitmap,
mappedImageInfo.X, mappedImageInfo.Y,
imageRect,
GraphicsUnit.Pixel);

spriteGraphics.Flush(FlushIntention.Flush);
}

imageInfo.DisposeBitmap();
}
}

此代码在本地与 azure 的计算模拟器完美配合。但是当我部署它并执行代码时,它不再工作,并且在 spriteGraphics.DrawImage 处失败,并出现著名的 ArgumentException“参数无效”。

出于测试目的,我记录了克隆图像位图的详细信息,以查看是否有不同。我发现本地和云中唯一不一样的是 .Flags -> 本地我有 77842 而在云中是 77846 所以看起来 ImageFlagsHasTranslucent 已设置,但如果这会导致云中的问题以及如何解决目前我还不知道。

也许有人可以帮我解决这个奇怪的问题?

提前致谢。

HeManNew

最佳答案

我想说,由于应用程序的性质及其运行位置,工作确实是一个难题。

这里的主要问题是您使用的类/API 来自 System.Drawing 命名空间,并且您必须知道此命名空间中的类是为与 Windows 窗体一起使用而设计的。它们不支持在 Windows 或 ASP.NET 服务中使用,因此只要您能够避免在 Windows Azure Web 角色或辅助角色中使用这些 API,这就是最佳选择。云应用程序主要是Web应用程序或在后台工作的应用程序,这是避免对System的类/api依赖的主要原因。绘图是关键,进一步依赖GDI使情况变得更加复杂。

如果 API 失败,那只是因为它在 Web 环境中不兼容,即使它可用。即使在 Windows Azure 文档中,也建议完全避免使用 System.Drawing 中的 API/类,如果您的代码中必须包含这些 API/类,并且您打算在自己的 Windows Azure 应用程序中使用这些类,则应该进行详尽的测试。

关于azure - 使用 DrawImage 的代码可以在本地运行,但在 Azure 中失败并出现 ArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12503583/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com