我创建了一个绘画画布
<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>
现在,在完成绘制后,我想将其保存到File +并想将其转换为c#代码中的pictureBox或Image或位图
我该怎么做?
已经尝试过
ImageBrush picture = (ImageBrush)PaintCanvas.Background;
Image a = (Image)picture;
System.Drawing.Bitmap btmap = (System.Drawing.Bitmap)picture;
我在StackOverFlow和Google中找到的所有东西
从Image转换为imageBrush
先感谢您
最佳答案
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);
}
关于c# - 如何将ImageBrush转换为图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39851568/