【问题标题】:VB.NET value type of 'bitmap' cannot be converted to 'string'“位图”的 VB.NET 值类型无法转换为“字符串”
【发布时间】:2021-02-27 09:50:09
【问题描述】:

我将图像存储到属性>资源,但是当我在我的代码中调用它时,我得到了错误

'bitmap'的值类型不能转换为'string'

           oSheet.Shapes.AddPicture(My.Resources.123_LOGO,
           Microsoft.Office.Core.MsoTriState.msoFalse,
            Microsoft.Office.Core.MsoTriState.msoCTrue, 0, 0, 940, 120)

你认为问题是什么? 我已经有这个了,但它不工作

Dim imge As New System.Drawing.Bitmap(700, 1500)
Dim g As Graphics = Graphics.FromImage(imge)
 oSheet.Shapes.AddPicture(g,
               Microsoft.Office.Core.MsoTriState.msoFalse,
                Microsoft.Office.Core.MsoTriState.msoCTrue, 0, 0, 940, 120)

【问题讨论】:

  • Shapes.AddPicture() 需要文件的路径(字符串)。你正在传递一个位图。
  • 我该怎么做?我已经尝试过这个 `Dim Image As String = Convert.ToString(My.Resources.Capture)`,但我很难
  • 为什么不使用imge.save("temp.bmp") 保存位图,然后使用Shapes.AddPicture("temp.bmp") 将其读取为文件,然后删除temp.bmp
  • 你能举个例子吗?

标签: vb.net


【解决方案1】:

这是我在 Word 文档应用程序中所做的。

        fName = "rKeyPoints32"
        img = My.Resources.ResourceManager.GetObject(fName)
        img.Save(ThisAddIn.LGPUserTempDir & fName & ".png")
        wApp.Selection.InlineShapes.AddPicture(ThisAddIn.LGPUserTempDir & fName & ".png")
        Kill(ThisAddIn.LGPUserTempDir & fName)
        img = Nothing

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 1970-01-01
    相关资源
    最近更新 更多