我正在尝试通过 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.