Is there any option how to DrawImage using CCITT tiff compression (using 1bit per pixel).
I can read and write 1bit tiff with ImageSharp with no problem, but when i create Image using XImage and DrawImage to PDF, it is stored as multi byte RGB image (which is much bigger and conversion takes longer).
I tried reading file directly with XImage.FromFile, but result is the same.
I tried the same scenario with iText7 and image is stored in PDF correctly in 1bit format and conversion takes about 3s.
Simple code for conversion with Ximage.FromFile (just single frame version):
using var image = XImage.FromFile(@"d:\tmp.tiff");
var gfx = XGraphics.FromPdfPage(page);
page.Width = image.PointWidth;
page.Height = image.PointHeight;
gfx.DrawImage(image, 0, 0, image.PointWidth, image.PointHeight);
Conversion of all frames:
using var outDoc = new PdfDocument();
using var img = Image.Load(inputFile.OpenReadStream(),
new TiffDecoder() {DecodingMode = FrameDecodingMode.All});
for (var i = 0; i < img.Frames.Count; i++)
{
var frameImg = img.Frames.CloneFrame(i) as Image<Rgba32>; CloneFrame returns rgba32
using var image =
XImage.FromImageSource(
ImageSharpImageSource<Rgba32>.FromImageSharpImage(frameImg, TiffFormat.Instance, 90));
var page = outDoc.AddPage();
var gfx = XGraphics.FromPdfPage(page);
page.Width = image.PointWidth;
page.Height = image.PointHeight;
gfx.DrawImage(image, 0, 0);
}
Is there any option how to DrawImage using CCITT tiff compression (using 1bit per pixel).
I can read and write 1bit tiff with ImageSharp with no problem, but when i create Image using XImage and DrawImage to PDF, it is stored as multi byte RGB image (which is much bigger and conversion takes longer).
I tried reading file directly with XImage.FromFile, but result is the same.
I tried the same scenario with iText7 and image is stored in PDF correctly in 1bit format and conversion takes about 3s.
Simple code for conversion with Ximage.FromFile (just single frame version):
Conversion of all frames:
Both versions result in the same big PDF.