2014-01-22 37 views
1

我有一個使用設備相機捕獲圖像的類。我的目標是將捕獲的圖像傳遞到另一個佈局上的畫布。如何將拍攝的圖像傳遞給畫布?

這個佈局將隨着一個輸入到一個文本框中的備註一起保存。我已經想出瞭如何保存備註和標題,並允許它被打開,但我不知道如何去通過捕獲圖像到佈局並與筆記一起保存。

有沒有人有任何建議或指針,我會怎麼去呢?

目前,這是我試圖讀取圖像文件回保存後的佈局,但我不知道如何將文件讀取到畫布中,所以顯然這種解決方案不工作又:

if (NavigationContext.QueryString.ContainsKey("note")) 
      { 
       string s2 = ".jpg"; 

       string filename = this.NavigationContext.QueryString["note"]; 
       if (!string.IsNullOrEmpty(filename)) { 
        using (var store = System.IO.IsolatedStorage.IsolatedStorageFile .GetUserStoreForApplication()) 
        using (var stream = new IsolatedStorageFileStream(filename, FileMode.Open, FileAccess.ReadWrite, store)) 


        /* 
        if(filename.Contains(s2)) 
        { 
         StreamReader reader = new StreamReader(stream); 
         this.capturedNoteCanvas = reader.ReadToEnd(); 
         this.noteNameTb.Text = filename; reader.Close(); 
        } 
        else 
        */ 
        { 
         StreamReader reader = new StreamReader(stream); 
         this.noteDataTb.Text = reader.ReadToEnd(); 
         this.noteNameTb.Text = filename; reader.Close(); 
        } 
       } 
      } 

我在想什麼是這樣的:

Proposed UI

+0

我可以問你到目前爲止所嘗試過的嗎? – philorube

+0

當然,我會在現在的問題中發佈我的解決方案。 –

回答

1

工作機智CameraCaptureTask和位圖

//從cameracapturetask

void cameracapturetask_Completed(object sender, PhotoResult e) 
     { 
      try 
      { 
       if (e.TaskResult == TaskResult.OK) 
       { 
        BitmapImage bmp = new BitmapImage(); 
        bmp.SetSource(e.ChosenPhoto); 
        WritableBitmap wb=new WritableBitmap (bmp.PixelWidth,bmp.PixelHeight); 
       } 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
     } 

隔空writableBitmap對象存儲節省WB

      using (MemoryStream stream = new MemoryStream()) 
          { 
           wb.SaveJpeg(stream, (int)bmp.PixelWidth, (int)bmp.PixelHeight, 0, 100); 
           using (IsolatedStorageFileStream local = new IsolatedStorageFileStream(App.PageName, FileMode.Create, mystorage)) 
           { 
            local.Write(stream.GetBuffer(), 0, stream.GetBuffer().Length); 
           } 
          } 

//從帆布

隔空WritableBitmap如果你的畫布包含圖像,也畫布它歸因於一些高度和寬度屬性,然後

WritableBitmap wb= new WritableBitmap(canvascontrol,null); 

需要畫布並將其保存在可寫的位圖對象中,然後可用於進一步的圖像操作。

相關問題