我画了一幅画布
<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>现在,在我画完它之后,我想将它保存到文件+,希望将它转换成pictureBox、图像或c#代码中的位图。
我是怎么做到的?
已试过
ImageBrush picture = (ImageBrush)PaintCanvas.Background;
Image a = (Image)picture;
System.Drawing.Bitmap btmap = (System.Drawing.Bitmap)picture;我在StackOverFlow和谷歌上找到的所有东西都从图像转换为imageBrush
提前谢谢你
发布于 2016-10-04 12:19:42
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);
}发布于 2016-10-04 12:05:33
试试下面的代码。可能对你有帮助。
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;
}https://stackoverflow.com/questions/39851568
复制相似问题