如何使用C#在WPF中将图像复制到剪贴板? [英] How to copy image to clipboard in WPF using C# ?

查看:527
本文介绍了如何使用C#在WPF中将图像复制到剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#在WPF中将图像复制到剪贴板?

我有一个带有图像的图像控件.需要帮助将图像从图像控件复制到剪贴板. :)

我尝试了一些来自Google的代码,但这些代码无法正常工作. :sigh:


技术:WPF,C#.Net

How to copy image to clipboard in WPF using C#?

I''ve an image control with an image.Need help to copy image from image control to clipboard. :)

I tried some code from google, those are not working. :sigh:


Technology: WPF, C#.Net

推荐答案

感谢Jaykay832 :-D

您的回答很简单.

Thanks Jaykay832 :-D

Your answer was straight forward.

double width = image1.ActualWidth;
            double height = image1.ActualHeight;
            RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 96, 96, PixelFormats.Default);
            DrawingVisual dv = new DrawingVisual();
            using (DrawingContext dc = dv.RenderOpen())
            {
                VisualBrush vb = new VisualBrush(image1);
                dc.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
            }
            bmpCopied.Render(dv);
            Clipboard.SetImage(bmpCopied);


[ ^ ]和
this[^] and Clipboard[^]might help you.


此外,请查看 [
In addition, have a look at this[^] tutorial.


这篇关于如何使用C#在WPF中将图像复制到剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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