打印画布以形成 silverlight 图像
我已使用 WritebleBitmap 类成功地将画布添加到位图,然后尝试使用位图通过 SaveFileDilogue 将图像保存在客户端系统上。我正在使用 FluxJpegCore 图像编码方法,其中我们使用栅格数组按像素生成图像。 下面是完成这项工作的代码部分。
byte[][,] raster = new byte[bands][,];
for (int i = 0; i < bands; i++)
{
raster[i] = new byte[width, height];
}
for (int row = 0; row < height; row++)
{
for (int column = 0; column < width; column++)
{
int pixel = bitmap.Pixels[width * row + column];
raster[0][column, row] = (byte)(pixel >> 16);
raster[1][column, row] = (byte)(pixel >> 8);
raster[2][column, row] = (byte)pixel;
}
}
图像保存一切顺利,但是当我缩放图像然后打印它时,代码在“raster[i] = new byte[width, height];”行失败。出现系统内存不足错误。谁能帮我找到这个问题的解决方案?
I have scuccesfully added canvas to bitmap using WritebleBitmap class and then trying to use the bitmap to save image on client system through SaveFileDilogue. I am using the method of FluxJpegCore image encoding where we use raster arrays to generate image pixel-wise.
Below is the part of the code which does the job.
byte[][,] raster = new byte[bands][,];
for (int i = 0; i < bands; i++)
{
raster[i] = new byte[width, height];
}
for (int row = 0; row < height; row++)
{
for (int column = 0; column < width; column++)
{
int pixel = bitmap.Pixels[width * row + column];
raster[0][column, row] = (byte)(pixel >> 16);
raster[1][column, row] = (byte)(pixel >> 8);
raster[2][column, row] = (byte)pixel;
}
}
All goes fine with image saving, however when i zoom the image and then print it, the code fails at the line "raster[i] = new byte[width, height];". System out of memory error is raised. Can anyone help me to find the solution on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定是否有解决方案。您有 3 个数组,每个数组都需要一个连续的 163MB 内存块。问题是进程没有 3 个这样大小的可用地址块。
还要记住,
bitmap.Pixels
将是一个 653MB 大的数组。您唯一真正的希望是使用
Stream
而不是字节数组,并且效率很高(您仍然需要做很多工作),I'm not sure there is a solution to be had. You have 3 arrays that each need a contiguous 163MB block of memory. The problem will be that the process does not have 3 such address blocks available that are that size.
Bear in mind also that the
bitmap.Pixels
will be an array 653MB big.Your only real hope(s) would be to
Stream
instead of a byte array and does so effeciently (still a lot of work for you to do there)与@AnthonyWJones 一起,我很确定宽度或高度类似于 double.NAN。确保检查宽度和高度是否为实数。还要检查您的数组在 Silverlight 中是否没有超出可能的范围
Going with @AnthonyWJones I'm pretty sure width or height is something like double.NAN. Make sure you place a check to see is width and height is a real number. Also check that your array does not a lot for more than possible within Silverlight