2013-08-23 171 views
0

嗨我正在開發一個鎖屏應用程序,我正在使用圖像列表框。選擇圖像後,當我點擊一個按鈕來設置鎖屏,它應該更新。但它更新bot。這裏是我的代碼LockScreen for windows phone 8

private async void ApplicationBarIconButton_Click(object sender, EventArgs e) 
    { 
     MediaLibrary mediaLibrary = new MediaLibrary(); 
     //ImageSource im = image1.Source; 
     BitmapImage bitmap = new BitmapImage(); 
     bitmap.SetSource(mediaLibrary.Pictures[imageList.SelectedIndex].GetImage()); 

     String tempJPEG = "MyWallpaper1.jpg"; 

     using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      if (myIsolatedStorage.FileExists(tempJPEG)) 
      { 
       myIsolatedStorage.DeleteFile(tempJPEG); 
      } 

      IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG); 

      StreamResourceInfo sri = null; 
      Uri uri = new Uri(tempJPEG, UriKind.Relative); 
      sri = Application.GetResourceStream(uri); 

      WriteableBitmap wb = new WriteableBitmap(bitmap); 

      Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 90); 

      fileStream.Close(); 
     } 

     LockScreenChange(tempJPEG); 

    } 

    private async void LockScreenChange(string filePathOfTheImage) 
    { 
     if (!LockScreenManager.IsProvidedByCurrentApplication) 
     { 
      await LockScreenManager.RequestAccessAsync(); 
     } 

     if (LockScreenManager.IsProvidedByCurrentApplication) 
     { 
      var schema = "ms-appdata:///Local/"; 
      var uri = new Uri(schema + filePathOfTheImage, UriKind.Absolute); 

      LockScreen.SetImageUri(uri); 
      var currentImage = LockScreen.GetImageUri(); 
      MessageBox.Show("Success", "LockScreen changed", MessageBoxButton.OK); 
     } 
     else 
     { 
      MessageBox.Show("Background cant be changed. Please check your permissions to this application."); 
     } 
    } 

實際上第一時間時該應用被啓動並且當我點擊設置按鈕,當前選擇的圖像被設定爲鎖屏,在此之後,當我選擇另一圖像,它顯示鎖屏變化,success.No錯誤,沒有例外,我不知道問題在哪裏。 請幫助........

+0

一個轉換異常解決意味着你使用了錯誤的類型。查看您使用的每種方法的返回類型,並確保它與方法參數需要的匹配。 –

回答

0

它得到了通過更改臨時文件名以原文件名即字符串tempJpeg