如何将picturebox.image作为jpeg放在剪贴板上? [英] How do I put a picturebox.image on the clipboard as a jpeg?

查看:117
本文介绍了如何将picturebox.image作为jpeg放在剪贴板上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在图片框中有一张图片.我需要将图像的副本作为JPEG放在剪贴板上.我想出了如何将其作为PNG进行操作,但JPEG版本不起作用.

这有效:

I have an image in a picture box. I need to put a copy of the image on the clipboard as a JPEG. I figured out how to do it as a PNG, but the JPEG version doesn''t work.

This works:

''Put the image in a memorystream. VpaResult.VpaImage is a picturebox.
Dim ms As IO.MemoryStream = New IO.MemoryStream
Call VpaResult.VpaImage.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Dim m_data As DataObject = New DataObject
Call m_data.SetData("PNG", True, ms)
Call Clipboard.SetDataObject(m_data, True)
''The image is on the clip board and can be pasted.
''TestReport is an Excel worksheet.
Call TestReport.PasteSpecial("Picture (PNG)")



这不起作用:



This does not work:

''Put the image in a memorystream. VpaResult.VpaImage is a picturebox.
Dim ms As IO.MemoryStream = New IO.MemoryStream
Call VpaResult.VpaImage.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim m_data As DataObject = New DataObject
''I tried both "JPEG" and "JPG". Neither works.
Call m_data.SetData("JPEG", True, ms)
Call Clipboard.SetDataObject(m_data, True)
''The image does not appear to be on the clip board and so cannot be pasted.
''TestReport is an Excel worksheet.
Call TestReport.PasteSpecial("Picture (JPEG)")



如果我可以jpeg格式获取图像,则生成的文件为250 KB而不是606 KB.



If I can get the images in as jpeg the resulting file is 250 KB instead of 606 KB.
Can you explain how to get the image on the clipboard as a jpeg?

推荐答案

这应该提供答案: ^ ].

抱歉,它是C#,但是如果您想获得一些好的帮助或代码示例,则需要至少了解一些C#.只是VB.NET不会对您有太大帮助.

毕竟,您需要知道的是:使用System.Windows.Forms.Clipboard.SetImage(对于System.Windows.Forms).对于WPF,这是System.Windows.Clipboard.SetImage.



方法SetImage以位图格式(在Windows中为CF_BITMAP,在public static readonly string System.Windows.Forms.DataFormats.Bitmap中)添加数据.这种格式对于所有位图都是通用的,与位图文件及其详细信息(例如压缩,质量损失等)无关.这与JPEG,PNG和BMP之间的差异无关.

有关剪贴板格式,请参见 http://msdn.microsoft.com/zh-我们/library/ms649013(v=vs.85).aspx [ http://msdn.microsoft.com/en-us/library/y444e6db. aspx [ ^ ].我不建议这样做;处理CB_BITMAP格式要好得多;无论它们支持哪种格式,都可以在系统中的所有应用程序之间交换图像和图像片段.

—SA
This should provide the answer: Clipboard handling with .NET[^].

Sorry, it is C#, but if you want to get some good help or code samples, you need to understand at least some of C#; just VB.NET won''t help you much.

After all, all you need to know is this: use System.Windows.Forms.Clipboard.SetImage (for System.Windows.Forms). For WPF, this is System.Windows.Clipboard.SetImage.



The methods SetImage adds data in the Bitmap format (CF_BITMAP in windows, public static readonly string System.Windows.Forms.DataFormats.Bitmap). This format is common for all bitmaps and has nothing to do with bitmap files and their details, such as compression, quality loss, etc. So the clipboard contains data about bitmap and not about bitmap file; this is irrelevant to the difference between JPEG, PNG and BMP.

About clipboard formats, see http://msdn.microsoft.com/en-us/library/ms649013(v=vs.85).aspx[^].

As you can see from this link, alternatively you can create (unregistered) private format, or register your custom format in the system. For more information, see: http://msdn.microsoft.com/en-us/library/y444e6db.aspx[^]. I do not recommend it; dealing with CB_BITMAP format is much better; it makes it possible to exchange images and image fragments between all applications in the system no matter what formats they support.

—SA


这篇关于如何将picturebox.image作为jpeg放在剪贴板上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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