I'm trying to convert DataGridView data with an image column which is filtered from my SQL database into a PDF file in C#. I wrote this code using iTextSharp, but I get an error
Unable to cast object of type System.Drawing.bitmap to type system byte[]
Can anyone kindly help me out?
Thanks.
Here is my code:
foreach (DataGridViewCell cell in row.Cells)
{
if(row.Cells[0].Value!= null)
{
pdfTable.AddCell(row.Cells[0].Value.ToString());
}
if (row.Cells[1].Value != null)
{
byte[] img = (byte[])row.Cells[1].Value;
pdfTable.AddCell(iTextSharp.text.Image.GetInstance(img));
}
}