我创建了一个绘画 Canvas
<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# 代码中的 pictureBox 或图像或位图
我该怎么做?
已经尝试过
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/