How to create an iTextSharp.text.Image object starting with a System.Drawing.Bitmap object?

I am new to iTextSharp (C # iText version):

I have something like this:

System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)ChartHelper.GetPdfChart((int)currentVuln.UrgencyRating * 10); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bitmap); vulnerabilityDetailsTable.AddCell(new PdfPCell(img) { Border = PdfPCell.RIGHT_BORDER, BorderColor = new BaseColor(79, 129, 189), BorderWidth = 1, Padding = 5, MinimumHeight = 30, PaddingTop = 10 }); 

As you can see, I have a classic System.Drawing.Bitmap called bitmap , and I want to put it in the cell of the PDF document table.

The problem is that this line is signed as an error:

 iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bitmap); 

Error:

Error 75 The best overloaded method matching for 'iTextSharp.text.Image.GetInstance (iTextSharp.text.Image)' has some invalid arguments c: \ Develop \ EarlyWarning \ public \ Implementazione \ Ver2 \ PdfReport \ PdfVulnerability.cs 120 27 PdfReport

Therefore, I think I need to get the iTextSharp.text.Image object from the classic System.Drawing.Bitmap object.

What can I do for this? I'm losing my mind trying to do this.

Tpx

+6
source share
1 answer

There are no overloads which occupy only System.Drawing.Image . You must use one of these:

 GetInstance(System.Drawing.Image image, BaseColor color) GetInstance(System.Drawing.Image image, BaseColor color, bool forceBW) GetInstance(System.Drawing.Image image, System.Drawing.Imaging.ImageFormat format) 

The first one is probably the best choice, and I'm 99% sure that you can pass null for the color parameter.

+15
source

All Articles