Create a portrait gallery
I want to create a portrait gallery with some photos. In order to achieve this, I add everything I need in a panel and then I get the visual of this panel to add it in a PDF.
My problem is that I managed to create the PDF containing the image, but it is bad quality.
We see that the outline of peoples is not clear, while in the original photos the outline is very clear.
iTextSharp.text.Document doc = new iTextSharp.text.Document(); panelTombi.AutoScrollPosition = new Point(0, 0); panelTombi.AutoSize = true; panelTombi.Refresh(); int width = panelTombi.Width; int height = panelTombi.Height; Bitmap MemoryImage = new Bitmap(width, height); panelTombi.DrawToBitmap(MemoryImage, new System.Drawing.Rectangle(0, 0, width, height)); iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance((System.Drawing.Image)MemoryImage, System.Drawing.Imaging.ImageFormat.Jpeg); image1.ScaleToFit(doc.PageSize); image1.SetAbsolutePosition(0, PageSize.A4.Height - image1.ScaledHeight - doc.TopMargin); MemoryImage.Save(Path.GetDirectoryName(sfd.FileName) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(sfd.FileName) + ".jpeg"); //Save pdf file PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create)); doc.Open(); doc.Add(image1); doc.Close();
As you can see, the image is also saved.
The image has always a good quality but some pixels are white:
But the PDF has always the same problem no matter the image format, the outline of people is not sharp.
Could you tell me how to fix this image quality problem on the PDF file?
Have you tested with iText7 (latest version of iTextSharp) ?
I did some tests with iText7 package by saving photos displayed in PictureBox in a Panel and the image quality seems good
I have just made the necessary modifications in order to use itext7 and I see that it actually works much better. I also found that the image is directly centered in the PDF and placed at the top of the page whereas with the old version I had to do a rough calculation and set the placement via a line of code.
I also noticed that the quality of some photos that I took is a bit low because I wanted to do it too fast without giving the camera time to focus (I took 360 photos ...). I have sometimes thought that this lack of quality is related to PDF.
This is not important as I need a PDF, but I have found that the BMP (or PNG or JPEG depending on what I want) image saved on my computer has white pixels in some places . Do you think that it is related to one of the colors present in certain photos which poses a problem? Because we see that some photos do not have this problem of white pixels.
I have no camera so I cannot test...
I tried to search on Google with keywords like "white pixels" "camera" or "webcam" bit I did not find any information about this problem
White pixels are not on the original photos and are not displayed in the software I created. The white pixels are only visible on the image resulting from saving everything displayed in the panel and only on the photo of certain people. So strange, because white pixels are not displayed in the PDF which displays the same as the picture.
If anyone has an idea I invite them to share their theory :)
Have you tried using other packages?
If this problem only appears in IText, it may be a problem with some rendering algorithms of this package, then you can raise an issue in their GitHub repository and ask them to check it.
Sign in to comment