簡體   English   中英

將 System.Drawing.Bitmap 轉換為 stdole.StdPicture

[英]Convert System.Drawing.Bitmap to stdole.StdPicture

我目前有一個 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 位進程中受支持。Z80791B3AE7002CB88F8C246876D9FAAA microsoft.com/fwlink/?linkid=160862

那么用什么代替呢? 我還沒有找到其他解決方案...

取自 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);
   }
} 

如果你在 Google 上搜索 [convert .net image to ole picture],你會發現一大堆關於另辟蹊徑的討論(即將 ole 圖片轉換為圖像),還有很多建議說,實際上, “不要嘗試在 .NET 中使用 ole 圖片”。 我同意。 幾年前我走上了這條路,並決定我真的不需要那么糟糕的 OLE 圖片。

我強烈建議您重新評估您對 OLE 圖片對象的需求。 如果要將圖像保存在數據庫中,請將它們存儲為 BLOB 而不是圖片對象。 如果您絕對必須使用 OLE 圖片對象,那么祝您好運。 這將是非常令人沮喪的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM