ITextSharp - How to enter an image (PNG) from a project resource?

I have iTextSharp creating pdf for me on VB.net. Everything worked great, but now I want to implement the image. I tried this:

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

This is mistake:

"GetInstance" cannot be called with these arguments

It seems to be expecting a path and getting the type System.Drawing.Bitmap.

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

+3
source share
1 answer

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

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)
+8

Source: https://habr.com/ru/post/1757845/


All Articles