2
每个人,在将图片保存到媒体库时遇到了一个奇怪的问题,我的应用程序崩溃而未出现异常。这是我的保存代码。WP7试图创建WriteableBitmap实例时出现崩溃
using (MemoryStream stream = new MemoryStream())
{
try
{
WriteableBitmap bitmap = new WriteableBitmap(InkPrest, InkPrest.RenderTransform); // Crash here, the actualHeight of InkPrest is 2370.0
bitmap.SaveJpeg(stream, (int)InkPrest.ActualWidth, (int)InkPrest.ActualHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
MediaLibrary library = new MediaLibrary();
library.SavePicture(DateTime.Now.ToString(), stream.GetBuffer());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我已经debuged一步一个脚印,在
WriteableBitmap bitmap = new WriteableBitmap(InkPrest, InkPrest.RenderTransform); // Crash here, the actualHeight of InkPrest is 2370.0
解决这个问题的任何想法的应用程序崩溃?
============================================
尝试保存多个图像
的UIElement是704 * 2370
TranslateTransform transform = new TranslateTransform();
transform.Transform(new Point(0,0));
double MaxHeight = 800;
double height = InkPrest.ActualHeight;
int saveCount = 0;
int succeedCount = 0;
while (height > 0)
{
using (MemoryStream stream = new MemoryStream())
{
try
{
double actualRenderHeight = Math.Min(height, MaxHeight);
WriteableBitmap bitmap = new WriteableBitmap((int)InkPrest.ActualWidth, (int)actualRenderHeight);
bitmap.Render(InkPrest, transform); //Crash here, also no exception.
bitmap.Invalidate();
height -= actualRenderHeight;
transform.Y -= actualRenderHeight;
bitmap.SaveJpeg(stream, (int)InkPrest.ActualWidth, (int)actualRenderHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
MediaLibrary library = new MediaLibrary();
Picture pic = library.SavePicture(manuscriptFile.Title + DateTime.Now.ToString(), stream.GetBuffer());
saveCount++;
if (pic != null)
{
succeedCount++;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
这是在模拟器上,还是只在真实的设备上? –
都在仿真器和设备上。崩溃没有例外。 – Wp7Beginner
我想碰撞共振是我的图片比2000年更久。我正在测试它。 – Wp7Beginner