如何将ImageBrush转换为图像

时间:2016-10-04 11:51:17

标签: c# wpf

我创建了一个彩绘画布

<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和谷歌上找到的所有东西 是从Image转换为imageBrush

提前谢谢

2 个答案:

答案 0 :(得分: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;
        }

答案 1 :(得分:1)

count_all = sum(cellfun(@(x) sum(x<ti & x>ti-INT), h));