question

JrmyR-7853 avatar image
0 Votes"
JrmyR-7853 asked TimonYang-MSFT commented

Create a portrait gallery

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.

https://i.stack.imgur.com/Wc57w.png
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


dotnet-csharp
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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

0 Votes 0 ·

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.

KItkjehOktA_Screenshot-1.png

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.


0 Votes 0 ·

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

0 Votes 0 ·
Show more comments

@JrmyR-7853
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.

0 Votes 0 ·

0 Answers