2011-01-29 4 views
0

내가 코드이미지 WP7에서 처리되지 않은 예외 오류가 발생하고 중복 된 이미지

private void wallpaper_Click(object sender, RoutedEventArgs e) 
    { 

     String imageName ="temjpeg";  I 

     // Create virtual store and file stream. Check for duplicate tempJPEG files. 
     var myStore = IsolatedStorageFile.GetUserStoreForApplication(); 
     if (myStore.FileExists(temjpeg)) 
     { 
      myStore.DeleteFile(temjpeg); 
     } 

     IsolatedStorageFileStream myFileStream = myStore.CreateFile(imageName); 


     // Create a stream out of the sample JPEG file. 
     // For [Application Name] in the URI, use the project name that you entered in        the previous steps. Also TestImage.jpg is an example, 
     //you must enter your JPEG filename if it is different. 
     StreamResourceInfo sri = null; 
     Uri uri = new Uri("some String",UriKind.Relative); 
     sri = Application.GetResourceStream(uri); 

     // Create a new WriteableBitmap object and set it to the JPEG stream. 
     BitmapImage bitmap = new BitmapImage(); 
     bitmap.SetSource(sri.Stream); 
     WriteableBitmap wb = new WriteableBitmap(bitmap); 


     // Encode WriteableBitmap object to a JPEG stream. 
     // SaveJpeg(WriteableBitmap bitmap, Stream targetStream, int targetWidth, int targetHeight, int orientation, int quality) 
     Extensions.SaveJpeg(wb, myFileStream, wb.PixelWidth, wb.PixelHeight, 0, 85); 
     myFileStream.Close(); 


     // Create a new stream from isolated storage, and save the JPEG file to the media library on Windows Phone. 
     myFileStream = myStore.OpenFile(temjpeg, FileMode.Open, FileAccess.Read); 

     MediaLibrary library = new MediaLibrary(); 

     Picture pic = library.SavePicture(imageName, myFileStream); 
     myFileStream.Close(); 
     } 

되어 다음 를 클릭 버튼을 WP7 폰에 이미지를 저장하려면 저장하지만이 코드 줄에 InvalidOperationException이 던졌습니다 : Picture pic = library.SavePicture (imageName, myFileStream); 무엇이 문제 일 수 있습니까? .. 예외 문제가 해결 된 후 저장 버튼을 여러 번 클릭하면 이미지가 여러 번 저장됩니다. 다른 사람이 도움을받을 수 있습니까?

답변

1

실제 핸드폰에서만 SavePicture가 에뮬레이터에서 작동하지 않으므로 에뮬레이터에서이 작업을 수행하고 있습니까?

+0

아니요. Windows Phone 7 장치에서이 작업을 수행하고 있습니다. – Shaireen

+0

USB 케이블을 연결 한 채로 잡고 있습니까? 그렇다면 사용하지 않고 사용해보십시오. –

+0

많은 사람에게 감사드립니다. .. 내 인생을 구해 줬어. ..하지만 한가지 더 .. 버튼을 클릭하면 이미지가 여러 번 저장됩니다.하지만 한 번만 저장하고 아무 것도하지 않으면 이미 저장합니다. . – Shaireen