2017-02-27 91 views
0

我已經設法從手機庫中選取圖像並顯示它。這是代碼。問題是如何將此圖像插入到我的Sqlite聯繫人數據庫中,並在獲取圖像後檢索並再次顯示它?這是我的代碼。從這裏可以瞭解詳細的分步說明。如何將位圖圖像插入到Windows Phone 8.1上的sqlite數據庫c#

 namespace Mobile_Life.Pages 
{ 

public sealed partial class NextOFKin_Update_Delete : Page 
    { 
     int Selected_ContactId = 0; 
     DatabaseHelperClass Db_Helper = new DatabaseHelperClass(); 
     Contacts currentcontact = new Contacts(); 
     CoreApplicationView view; 

     public NextOFKin_Update_Delete() 
     { 
      this.InitializeComponent(); 
      HardwareButtons.BackPressed += HardwareButtons_BackPressed; 
      view = CoreApplication.GetCurrentView(); 

     } 

     private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e) 
     { 
      if (Frame.CanGoBack) 
      { 
       e.Handled = true; 
       Frame.GoBack(); 
      } 
     } 

     protected override async void OnNavigatedTo(NavigationEventArgs e) 
     { 
      await StatusBar.GetForCurrentView().ShowAsync(); 
      Selected_ContactId = int.Parse(e.Parameter.ToString()); 
      currentcontact = Db_Helper.ReadContact(Selected_ContactId);//Read selected DB contact 
      namestxt.Text = currentcontact.Name;//get contact Name 
      relationtxt.Text = currentcontact.Relation;//get contact relation 
      phonetxt.Text = currentcontact.PhoneNumber;//get contact PhoneNumber 

     } 

     private void Update_click(object sender, RoutedEventArgs e) 
     { 
      currentcontact.Name = namestxt.Text; 
      currentcontact.Relation = relationtxt.Text; 
      currentcontact.PhoneNumber = phonetxt.Text; 
      Db_Helper.UpdateContact(currentcontact);//Update selected DB contact Id 
      Frame.Navigate(typeof(NextOfKin)); 
     } 

     private void Delete_click(object sender, RoutedEventArgs e) 
     { 
      Db_Helper.DeleteContact(Selected_ContactId);//Delete selected DB contact Id. 
      Frame.Navigate(typeof(NextOfKin)); 
     } 

     private void profile_img(object sender, TappedRoutedEventArgs e) 
     { 
      FileOpenPicker filePicker = new FileOpenPicker(); 
      filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; 
      filePicker.ViewMode = PickerViewMode.Thumbnail; 

      // Filter to include a sample subset of file types 
      filePicker.FileTypeFilter.Clear(); 
      filePicker.FileTypeFilter.Add(".bmp"); 
      filePicker.FileTypeFilter.Add(".png"); 
      filePicker.FileTypeFilter.Add(".jpeg"); 
      filePicker.FileTypeFilter.Add(".jpg"); 

      filePicker.PickSingleFileAndContinue(); 
      view.Activated += viewActivated; 
     } 

     private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1) 
     { 
      FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs; 

      if (args != null) 
      { 
       if (args.Files.Count == 0) return; 

       view.Activated -= viewActivated; 
       StorageFile storageFile = args.Files[0]; 
       var stream = await storageFile.OpenAsync(FileAccessMode.Read); 
       var bitmapImage = new BitmapImage(); 
       await bitmapImage.SetSourceAsync(stream); 

       var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream); 
       profile.ImageSource = bitmapImage; 


      } 
     } 

    } 
+0

爲什麼不只是保存的路徑是在手機圖書館到SQLite數據庫中的圖像,而不是試圖同圖像本身? – gattsbr

+0

會試一試。雖然用戶從手機中刪除圖像會不會受到影響? –

回答

相關問題