剪贴板和外部图像 [英] Clipboard and External Images

查看:86
本文介绍了剪贴板和外部图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了意外的挑战.我正在尝试将来自外部源(即Explorer/MSPaint/IE)的图像复制到vs2010 C#应用程序Win Form图像控件中.我认为这不是一个罕见的功能.如果我将图像从C#应用程序复制到剪贴板,则访问它没有任何问题.但是,复制到应用程序外部剪贴板中的同一图像将返回Clipboard.GetImage()的null值,以及包含ContainsImage()的false值.文本仍然有效.我读到的所有内容都说这不是安全问题.我所做的一切都指向这种方式.大小和格式不是问题.

MSDB和Google几乎没有帮助.我找不到任何示例代码.我正在运行Win7/64 4GB RAM.

我一定会很感激的线索

TomTheTeacher

I am having an unexpected challenge. I am trying to copy an image from an external source (i.e. Explorer/MSPaint/IE) into a vs2010 C# app Win Form image control. I would assume this is not an uncommon feature. If I copy the image onto the clipboard from the C# app I have no issues accessing it. But the same image copied to the clipboard outside the app returns a null with Clipboard.GetImage() as well as false from ContainsImage(). Yet text works. Everything I read says it is not a security issue. Everything I do points that way. Size and format is not an issue.

MSDB and Google have been of little help. None of the sample code I can find works. I am running Win7/64 4GB RAM.

I would sure appreciate leads

TomTheTeacher

推荐答案

我发现的最大原因是编码人员期望剪贴板上有一个图像,然后再进一步挖掘找到一个图像.而是文件路径.

您可以快速构建一个工具,以查看剪贴板上的数据格式.只需创建一个带有Button和ListBox的Windows Forms应用,然后将以下代码放入Button Click事件处理程序中即可:
The biggest cause of this that I''ve found is the coder expecting there to be an image on the clipboard only to find, with further digging, a filepath instead.

You can build a tool really quick to see what data formats are on the clipboard. Just create a Windows Forms app with a Button and a ListBox on it and drop the following code in the Button Click event handler:
IDataObject dataObject = Clipboard.GetDataObject;

if (dataObject != null) {
	ListBox1.Items.Clear();
	ListBox1.Items.AddRange(dataObject.GetFormats(true));
}



GetFormats()调用中的true不仅会列出剪贴板上对象可用的数据格式,而且还会列出数据可以自动转换为的格式.

对于图像,通常会查找DeviceIndependantBitmap.



The true in the GetFormats() call will list not only the data formats that are available for the object on the clipboard but also the formats that the data can be automatically converted to.

For an image, you''d normally look for DeviceIndependantBitmap.


事实证明,将图像复制到剪贴板时,无论是在资源管理器中,还是在网页之外,等等,您不是在复制映像本身,而是复制映像的路径.它永远不会在剪贴板上放置图像.令我感到惊讶的是,关于这一点没有太多的疑问.一旦我找到了字符串路径,它就可以正常工作.

问候,

TomTheTeacher
As it turns out, when you copy an image to the clipboard, be it in Explorer, off a Web page, etc., you are not copying the image itself but rather the path to the image. It never places an image on the clipboard. I am surprized there is not much nore written on this. Once I looked for the string path it worked fine.

Regards,

TomTheTeacher


这篇关于剪贴板和外部图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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