2013-02-11 1 views
2

내 응용 프로그램 mainpage의 image1이라는 이미지 컨트롤에서 전화의 미디어 라이브러리로 이미지를 저장하려고합니다. 내 코드는 WriteableBitmap wr = image1입니다. 그것은 나에게 오류를 준다. 오류 (그들은 2 개 개의 다른 종류)가 왜 당신은 WriteableBitmap 객체에 Control "image1에"를 할당하려고Windows phone에서 미디어 라이브러리에 이미지 저장 7

public void SaveImageTo(string fileName = "Gage.jpg") 
{ 
    fileName += ".jpg"; 
    var myStore = IsolatedStorageFile.GetUserStoreForApplication(); 
    if (myStore.FileExists(fileName)) 
    { 
     myStore.DeleteFile(fileName); 
    } 

    IsolatedStorageFileStream myFileStream = myStore.CreateFile(fileName); 
    WriteableBitmap wr = image1; // give the image source 
    wr.SaveJpeg(myFileStream, wr.PixelWidth, wr.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(fileName, FileMode.Open, FileAccess.Read); 
    MediaLibrary library = new MediaLibrary(); 
    //byte[] buffer = ToByteArray(qrImage); 
    library.SavePicture(fileName, myFileStream); } 

답변

0

, 즉이다.

"image1"원본의 설정 방식에 따라 WriteableBitmap을 다르게 초기화해야합니다.

"image1에는"로컬 이미지를 참조하는 경우, 당신이 그런 식으로 대응 WriteableBitmap을 초기화 할 수 있습니다 :

당신이 WriteableBitmap에 이미지 컨트롤을 렌더링 하려면
BitmapImage img = new BitmapImage(new Uri(@"images/yourimage.jpg", UriKind.Relative)); 
img.CreateOptions = BitmapCreateOptions.None; 
img.ImageOpened += (s, e) => 
{ 
    WriteableBitmap wr = new WriteableBitmap((BitmapImage)s); 
}; 

, 당신이 할 수 있습니다 :

WriteableBitmap wr = new WriteableBitmap(image1, null); 
+0

대단 했어요! – user2015167