将图像从 WinForms 应用程序导出到 PowerPoint 并具有透明度

发布于 2024-09-13 22:01:40 字数 589 浏览 20 评论 0原文

我在将应用程序中的图像粘贴到 PowerPoint 中并同时保持透明度时遇到问题。我有一个存储为 System.Drawing.Graphics 类型的图像,然后将其转换为 System.Drawing.Bitmap 类型并复制到剪贴板。在此过程中,我还使用 Bitmap.MakeTransparent(Color.Black) ,以便在粘贴图像时原始文档中的所有黑色内容都将变为透明。

if (GraphicsInterface.getGraphics() != null)
{
    Image image = GraphicsInterface.getGraphics();
    Bitmap bitmap = new Bitmap(image);
    bitmap.MakeTransparent(Color.Black);
    Clipboard.SetImage(bitmap);
}

然而,当我尝试将图像粘贴到 PowerPoint 等应用程序中时,所有黑色的内容现在都变成了非常浅的灰色,而不是透明的。

我的做法正确吗?有没有办法协调 .net 和 PowerPoint 中的透明值?或者将图像插入 PowerPoint 后是否必须手动完成透明度?

I've been having trouble pasting an image from my application into PowerPoint, while preserving transparency. I have an image stored as a System.Drawing.Graphics type which I then convert to a System.Drawing.Bitmap type and copy to the clipboard. During this process I also use Bitmap.MakeTransparent(Color.Black) so that everything in the original document which was black will be transparent when the image is pasted.

if (GraphicsInterface.getGraphics() != null)
{
    Image image = GraphicsInterface.getGraphics();
    Bitmap bitmap = new Bitmap(image);
    bitmap.MakeTransparent(Color.Black);
    Clipboard.SetImage(bitmap);
}

However, when I try to paste the image into an application like PowerPoint, instead of being transparent, everything that was black is now a very light gray.

Is my approach correct? Is there a way to reconcile the transparent values in .net and PowerPoint? Or will the transparency have to be done manually once the image is inserted to PowerPoint?

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

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

发布评论

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

评论(1

雨后咖啡店 2024-09-20 22:01:40

我能够通过加载已知良好的透明文件来重现此问题。我进行了一些搜索,最后找到了一些方法,可以将图像以透明方式粘贴到剪贴板上,然后我成功地将其粘贴到 PowerPoint 2007 中。

您可能仍然需要使用 MakeTransparent() 操作进行一些操作,但这应该可以帮助您入门。另外,不要忘记正确处理图像。为了清楚起见,我省略了 using 语句。

Image image = Image.FromFile(@".\Star.png");
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Png);
DataObject data = new DataObject("PNG", stream);
Clipboard.SetDataObject(data, true);

I was able to reproduce this issue by loading a known good file with transparency. I searched around a little bit and finally was able to come up with something that got the image onto the clipboard with transparency, which I then pasted into PowerPoint 2007 successfully.

You may still need to work some magic with the MakeTransparent() operation, but this should get you started. Also, don't forget to dispose of the images properly. I omitted using statements for clarity.

Image image = Image.FromFile(@".\Star.png");
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Png);
DataObject data = new DataObject("PNG", stream);
Clipboard.SetDataObject(data, true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文