如何将System.Windows.Controls.Image存储到本地磁盘 [英] How to store System.Windows.Controls.Image to local disk

查看:72
本文介绍了如何将System.Windows.Controls.Image存储到本地磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将System.Windows.Controls.Image存储到磁盘上,位置为:C:\ data \ 1.jpg 谢谢

How can i store a System.Windows.Controls.Image to disk say at location: C:\data\1.jpg Thanks

推荐答案

也许可以尝试以下方法:

Maybe try something along the lines of this method:

private void SaveImageToJPEG(Image ImageToSave, string Location)
        {
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)ImageToSave.Source.Width,
                                                                           (int)ImageToSave.Source.Height,
                                                                           100, 100, PixelFormats.Default);
            renderTargetBitmap.Render(ImageToSave);
            JpegBitmapEncoder jpegBitmapEncoder = new JpegBitmapEncoder();
            jpegBitmapEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
            using (FileStream fileStream = new FileStream(Location, FileMode.Create))
            {
                jpegBitmapEncoder.Save(fileStream);
                fileStream.Flush();
                fileStream.Close();
            }
        }

您可能需要弄乱RenderTargetBitmap中的大小才能获得所需的内容,但这应该可以完成工作.您不仅可以使用JpegBitmapEncoder,还可以使用其他编码器.

You might need to mess around with the sizes in RenderTargetBitmap to get what you want, but this should get the job done. You can use different encoders than just JpegBitmapEncoder too.

这篇关于如何将System.Windows.Controls.Image存储到本地磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆