本文介绍了iTextSharp - 如何从项目资源输入图像(PNG)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有iTextSharp在VB.net中为我创建一个pdf。一切都在着名,除了现在我想嵌入一个图像。我试过这个:

I have iTextSharp creating a pdf for me in VB.net. Everything was working famously, except now I want to embed an image. I tried this:

Dim test = My.Resources.MyImage
Dim logo = Image.GetInstance(test)

这是一个错误:

看起来好像它需要一条路径,并且正在获得一个System.Drawing.Bitmap类型。

It appears as though it expects a path, and is getting a System.Drawing.Bitmap type.

有什么方法可以将项目资源图像添加到我的PDF中吗?提前致谢!

Is there any way that I can add a project resource image to my PDF? Thanks in advance!

推荐答案

iTextSharp.text.Image.GetInstance()接受 System.Drawing.Image ,因此将PNG资源转换为此类型然后使用此重载。这样的事情:

One of the overloads for iTextSharp.text.Image.GetInstance() takes an System.Drawing.Image, so convert your PNG resource into this type and then use this overload. Something like this:

Dim test As System.Drawing.Image = System.Drawing.Image.FromHbitmap(My.Resources.MyImage.GetHbitmap())
Dim logo As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(test, System.Drawing.Imaging.ImageFormat.Png)

这篇关于iTextSharp - 如何从项目资源输入图像(PNG)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:26