2012-05-01 7 views
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); 
    } 
} 

I 단계,

WriteableBitmap bitmap = new WriteableBitmap(InkPrest, InkPrest.RenderTransform); // Crash here, the actualHeight of InkPrest is 2370.0 

이 문제 해결에 어떤 생각에서 응용 프로그램 충돌에 의해 단계 디버그하는 한?

===========================================

시도가 여러 이미지

을 저장

UIElement에가 * 2370 (704) 당신이 uithread 또는 다른 만든 스레드에서 writeablebitmap 인스턴스화 여부

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); 
     } 
    } 
} 
+0

에뮬레이터 또는 실제 장치에서만 가능합니까? –

+0

에뮬레이터와 장치 모두. whithout 예외. – Wp7Beginner

+0

내 생각에 내 사진이 2000 년보다 길다는 생각이 들었습니다. 나는 그것에 대해 테스트하고 있습니다. – Wp7Beginner

답변

0

확인합니다. 당신은 uithread에 writeablebitmap을 생성해야한다.

관련 문제