值不在WriteableBitmap的范围异常范围内

时间:2014-06-30 11:22:43

标签: c# xaml windows-phone-8 writeablebitmap

我在WindowsPhone应用程序中使用WriteableBitmap将UIElement转换为WriteableBitmap。我在以下代码中随机获取Value不在预期范围内的异常。但我无法找到根本原因。你能帮助我吗?

Size imageSize = new Size(element.ActualWidth, element.ActualHeight);

WriteableBitmap image = new WriteableBitmap((int)imageSize.Width, (int)imageSize.Height);
image.Render(element, null);
image.Invalidate();
return image;

1 个答案:

答案 0 :(得分:0)

试试这个:

WriteableBitmap image = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
image.Render(element, new MatrixTransform());
image.Invalidate();
return image;