【发布时间】:2015-12-29 18:45:16
【问题描述】:
我正在尝试通过 C# Visual Studio 2013 WPF 中的以下函数为地图图块构建位图。
https://msdn.microsoft.com/en-us/library/ms616045%28v=vs.110%29.aspx
public static BitmapSource Create(int pixelWidth, int pixelHeight, double dpiX, double dpiY, PixelFormat pixelFormat, BitmapPalette palette, Array pixels, int stride);
pixelWidth = tile.Image.Width; //value is 524288
pixelHeight = tile.Image.Height; //value is 524288
dpiX = 96;
dpiY = 96;
System.Windows.Media.PixelFormat pixelFormat = new System.Windows.Media.PixelFormat();
pixelFormat = System.Windows.Media.PixelFormats.Pbgra32;
pngBuffer is a Byte[] that has 778 integer elements
stride = 1024
但是,我得到了错误:
An unhandled exception of type 'System.ArgumentException' occurred in PresentationCore.dll
Additional information: Value does not fall within the expected range
我应该改变什么“价值”才能创建图像?
的帖子http://stackoverflow.com/questions/28490203/throws-an-exception-when-cropping-an-image-if-window-is-maximized-wpf
http://stackoverflow.com/questions/24613246/system-argumentexception-occurred
帮不了我。
谢谢
更新 我做了以下更改:
pixelWidth = 256
pixelHeight = 256
stride =1024 because stride = pixelWidth * (bitsPerPixel/ 8)
我收到错误:
An unhandled exception of type 'System.ArgumentException' occurred in PresentationCore.dll
Additional information: Buffer size is not sufficient.
【问题讨论】:
-
尺寸可能太大,因为这会产生 1Gb 的图像。使用 ImageMagick,您可以处理巨大的图像。
-
@Aybe,如果我将宽度和高度更改为 256,则会出现错误:PresentationCore.dll 中发生“System.ArgumentException”类型的未处理异常,附加信息:缓冲区大小不足。
标签: c# wpf visual-studio bitmap bitmapsource