How to create a iTextSharp.text.Image object startng to a System.Drawing.Bitmap object?

有些话、适合烂在心里 提交于 2019-12-04 02:59:05

问题


I am pretty new in iTextSharp (the C# version of iText):

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 classic System.Drawing.Bitmap immage named bitmap and I want put it inside a cell of a PDF document table.

The problem is that this line is signed as error:

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

The error is:

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

So I think that I need to obtain an iTextSharp.text.Image object from a classic System.Drawing.Bitmap object.

What can I do to do it? I am going crazy trying to do it.

Tnx


回答1:


There are no overloads that take just a System.Drawing.Image. You need to used 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 you can pass null for the color parameter.



来源:https://stackoverflow.com/questions/23548166/how-to-create-a-itextsharp-text-image-object-startng-to-a-system-drawing-bitmap

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