iTextSharp - How to input image (PNG) from project resource?

耗尽温柔 提交于 2020-01-01 15:56:08

问题


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)

This an error though:

'GetInstance' cannot be called with these arguments

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

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


回答1:


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)


来源:https://stackoverflow.com/questions/3398047/itextsharp-how-to-input-image-png-from-project-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!