剪贴板和外部图像

剪贴板和外部图像

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

问题描述

我遇到了意外的挑战.我正在尝试将来自外部源(即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

推荐答案

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.



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

08-31 09:26