Create a portrait gallery

Jérémy R 1 Reputation point
2021-09-18T17:09:37.127+00:00

Hello,

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.


6lkAa.png

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:
https://cjoint.com/doc/21_09/KIsrjgtryzv_index.png
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?

Thank you

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,292 questions
{count} votes