我正在使用以下C#代码从剪贴板复制图像。
我从这里获得了这段代码:这里。控制流确实进入了if条件语句。
我还尝试了以下代码片段。
这个也不起作用。
if (Clipboard.ContainsData(System.Windows.DataFormats.EnhancedMetafile))
{
/* taken from http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/a5cebe0d-eee4-4a91-88e4-88eca9974a5c/excel-copypicture-and-asve-to-enhanced-metafile*/
var img = (System.Windows.Interop.InteropBitmap)Clipboard.GetImage();
var bit = Clipboard.GetImage();
var enc = new System.Windows.Media.Imaging.JpegBitmapEncoder();
var stream = new FileStream(fileName + ".bmp", FileMode.Create);
enc.Frames.Add(BitmapFrame.Create(bit));
enc.Save(stream);
}
我从这里获得了这段代码:这里。控制流确实进入了if条件语句。
Clipboard.GetImage()
返回null。请问有人能够建议一下出现了什么问题吗?我还尝试了以下代码片段。
Metafile metafile = Clipboard.GetData(System.Windows.DataFormats.EnhancedMetafile) as Metafile;
Control control = new Control();
Graphics grfx = control.CreateGraphics();
MemoryStream ms = new MemoryStream();
IntPtr ipHdc = grfx.GetHdc();
grfx.ReleaseHdc(ipHdc);
grfx.Dispose();
grfx = Graphics.FromImage(metafile);
grfx.Dispose();
这个也不起作用。