2016-10-04 123 views
1

我創建了一個彩繪帆布如何圖像刷轉換爲圖像

<Canvas Grid.Row="1" Name="PaintCanvas" MouseDown="PaintCanvas_MouseDown" MouseUp="PaintCanvas_MouseUp" MouseMove="PaintCanvas_MouseMove"> 
     <Canvas.Background> 
      <ImageBrush ImageSource="/MyNoteBook;component/Images/LinnedPage.png"/> 
     </Canvas.Background> 

後,現在我完成畫上它,我想將它保存到文件+想把它轉換爲圖片框或圖像或位圖中的C#代碼

我該怎麼做?

已經嘗試過

ImageBrush picture = (ImageBrush)PaintCanvas.Background; 
Image a = (Image)picture; 
System.Drawing.Bitmap btmap = (System.Drawing.Bitmap)picture; 

所有的事情我在計算器上,並在發現谷歌 是從圖像轉換爲圖像刷

預先感謝您

回答

1
ImageBrush b = (ImageBrush)PaintCanvas.Background; 
BitmapSource src = (BitmapSource)b.ImageSource; 

string path = @"g:\myimg-name.jpg"; 
using (FileStream fs1 = new FileStream(path, FileMode.OpenOrCreate)) 
{ 
    BitmapFrame frame = BitmapFrame.Create(src); 

    JpegBitmapEncoder enc = new JpegBitmapEncoder(); 
    enc.Frames.Add(frame); 
    enc.Save(fs1); 
} 
+0

沒有幫助, 它只保存背景圖像和沒有的東西我畫 因爲在這裏看到 HTTP://image.prntscr。 com/image/43adfa4708ba4568b89a8755b348b294.png –

+0

但你回答我的第二個問題 獲取圖像使用它(找到一種方法與您的代碼將其翻譯成圖片) ty –

+0

@AsafShazar我發佈了你問的。問你的問題作爲單獨的問題,我會盡力回答它。 – AnjumSKhan

2

試試下面的代碼。它可以幫助你。

if (((Grid)sender).Children.Count > 0) 
     { 
      gridBackground = (ImageBrush)(((Grid)sender).Background); 
      System.Windows.Controls.Image gridBackImage = new System.Windows.Controls.Image(); 
      gridBackImage.Source = gridBackground.ImageSource; 

      ImageCar.Source = gridBackImage.Source; 
     } 
+0

Srry不幫我, 仍然無法獲得圖像 –

相關問題