将内存中的 BMP 转换为 PNG,以便在 .Net 中进行剪贴板粘贴

发布于 2024-09-15 04:14:06 字数 662 浏览 2 评论 0原文

这个类似问题的答案都需要保存文件。但是,我正在尝试转换文件,然后将其复制到剪贴板。

如何将位图(或任何图像)转换为 PNG 而不将其保存到文件系统?

更新:
我正在尝试将图像粘贴到应用程序中(在本例中为 Evernote)。当您将图像复制到剪贴板(例如通过浏览器)时,它会记住其图像格式,并且当您将其粘贴时,它将创建具有相同格式的图像。例如,如果您复制 PNG,它将粘贴 PNG。如果你复制 JPG,它会粘贴 JPG 等。

我试图获取剪贴板中当前的任何图像,将其缩放到我想要的大小,然后将其作为 PNG 保存在剪贴板中,这样当它粘贴到 Evernote 中,它将创建一个 PNG。

当我在浏览器中复制 PNG 图像时,我看到以下格式:HTML FORMATCF_BITMAPCF_DIBCF_DIBV5代码>.我不确定 Evernote 使用哪一个进行粘贴。我的印象是它是 CF_BITMAP,但在阅读下面的评论后,我猜它使用的是其他格式之一。

如何将图像放入剪贴板,粘贴时将被视为 PNG?

This similar question's answers all require the file to be saved. However, I'm trying to convert the file and then copy it to the clipboard.

How can I convert a Bitmap (or any image) to a PNG without saving it to the file system?

Update:
I'm trying to paste the image into an application (in this case Evernote). When you copy an image into the clipboard (e.g. via the browser), it remembers its image format and when you paste it in, it will create an image with the same exact format. For example, if you copy a PNG, it will paste a PNG. If you copy a JPG, it will paste a JPG, etc.

I am trying to take whatever image is currently in the clipboard, scale it to the size I want, and then keep it in the clipboard as a PNG, such that when it is pasted into Evernote, it will create a PNG.

When I copy a PNG image in my browser, I see the following formats: HTML FORMAT, CF_BITMAP, CF_DIB, CF_DIBV5. I'm not sure which of these Evernote is using for pasting. I was under the impression that it was CF_BITMAP, but after reading the comments below, I guess it's using one of the other formats.

How can I place an image in the clipboard which will be treated as a PNG when pasted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林迷了鹿 2024-09-22 04:14:06

位图保存到MemoryStream

byte[] result = null;
using (MemoryStream stream = new MemoryStream())
{
    bitmap.Save(stream, ImageFormat.Png);
    result = stream.ToArray();
}

Save the Bitmap to a MemoryStream

byte[] result = null;
using (MemoryStream stream = new MemoryStream())
{
    bitmap.Save(stream, ImageFormat.Png);
    result = stream.ToArray();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文