I have a task to extract black and white (1 bpc) image from PDF to jpg and tiff using .Net. But I got an exception when creating a bitmap from the memory steam.
The below is parts of my code
PdfImageXObject imageObject = imageData.GetImage();
if (imageObject == null)
{
Console.WriteLine("Image could not be read.");
}
else
{
ImageData image = ImageDataFactory.Create(imageObject.GetImageBytes());
using (var ms = new MemoryStream(image.GetData()))
{
Bitmap temp = new Bitmap(ms); //Exception threw from here, and the message was "Parameter is not valid."
//do the conversion.....
}
}
I use iText 7 to handle the PDF parts and the program works properly on grayscale and color images. I know the 1bpc images are classificed as rawimage, but have no clue on how to handle them. And I tried to append a header to the byte array returned from image.GetData() and expect the bitmap know what are they but with no luck.
Could anyone give me suggestion?