如何图像刷转换为图像
问题描述:
我创建了一个彩绘帆布如何图像刷转换为图像
<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;
所有的事情我在计算器上,并在发现谷歌 是从图像转换为图像刷
预先感谢您
答
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);
}
答
试试下面的代码。它可以帮助你。
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不帮我, 仍然无法获得图像 –
没有帮助, 它只保存背景图像和没有的东西我画 因为在这里看到 HTTP://image.prntscr。 com/image/43adfa4708ba4568b89a8755b348b294.png –
但你回答我的第二个问题 获取图像使用它(找到一种方法与您的代码将其翻译成图片) ty –
@AsafShazar我发布了你问的。问你的问题作为单独的问题,我会尽力回答它。 – AnjumSKhan