将 System.Drawing.Bitmap 转换为 stdole.StdPicture

发布于 2024-11-09 16:59:48 字数 630 浏览 4 评论 0原文

我当前有一个 System.Drawing.Bitmap,我需要将其转换为 stdole.StdPicture。
目前我正在使用:

var pic = (stdole.StdPicture)Microsoft.VisualBasic.Compatibility.VB6.Support.ImageToIPicture
                   (MyDLL.Properties.Resources.Img); // this is a System.Drawing.Bitmap

但我收到编译器警告:

警告“Microsoft.VisualBasic.Compatibility.VB6.Support.ImageToIPicture(System.Drawing.Image)”已过时:“Microsoft.VisualBasic.Compatibility.* 类已过时,仅在 32 位进程中受支持。http://go.microsoft.com/fwlink/?linkid=160862

那么该用什么来代替?我找不到其他解决方案然而...

I have a System.Drawing.Bitmap currently and I need to convert it into an stdole.StdPicture.
Currently I'm using:

var pic = (stdole.StdPicture)Microsoft.VisualBasic.Compatibility.VB6.Support.ImageToIPicture
                   (MyDLL.Properties.Resources.Img); // this is a System.Drawing.Bitmap

but I get a Compiler Warning:

Warning 'Microsoft.VisualBasic.Compatibility.VB6.Support.ImageToIPicture(System.Drawing.Image)' is obsolete: '"Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only. http://go.microsoft.com/fwlink/?linkid=160862

So what to use instead? I couldn't find another solution yet...

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

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

发布评论

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

评论(2

苦行僧 2024-11-16 16:59:48

摘自 NetOffice http://netoffice.codeplex.com Office 插件示例

public class IconConverter : System.Windows.Forms.AxHost
{
   private IconConverter(): base(string.Empty)
   {
   }

   public static stdole.IPictureDisp GetIPictureDispFromImage(System.Drawing.Image image)
   {

      return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
   }
} 

taken from NetOffice http://netoffice.codeplex.com Office Addin Example

public class IconConverter : System.Windows.Forms.AxHost
{
   private IconConverter(): base(string.Empty)
   {
   }

   public static stdole.IPictureDisp GetIPictureDispFromImage(System.Drawing.Image image)
   {

      return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
   }
} 
救赎№ 2024-11-16 16:59:48

如果您在 Google 上搜索 [将 .net 图像转换为 ole 图片],您会发现大量关于采用其他方式(即将 ole 图片转换为图像)的讨论,以及很多建议,其中效果,“不要尝试在.NET 中使用 ole 图片”。我同意。几年前,我沿着这条路走下去,并决定我并不那么需要 OLE 图片。

我强烈建议您重新评估对 OLE 图片对象的需求。如果要将图像保存在数据库中,请将它们存储为 BLOB 而不是图片对象。如果您绝对必须使用 OLE 图片对象,那么祝您好运。这将会非常令人沮丧。

If you do a Google search for [convert .net image to ole picture], you'll find a whole lot of chatter about going the other way (i.e. converting an ole picture to image), and a lot of advice that says, in effect, "don't try to use ole pictures in .NET". I concur. I went down that path a few years ago and decided that I didn't really need the OLE picture that badly.

I strongly recommend that you re-evaluate your need for OLE picture objects. If you're saving images in a database, store them as BLOBs rather than as picture objects. If you absolutely have to use OLE picture objects, then good luck. It's going to be very frustrating.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文