How to embed System.Drawing.Bitmap while preserving the full image quality?

Q:

I add a System.Drawing.Bitmap to the PDF as follows:

public void AddPicture_(double Left, double Bottom, Bitmap bmp, float
Divider) {
        //Obj _JBIG2_hint = Obj.CreateArray();
        //_JBIG2_hint.PushBack(Obj.CreateName("JBIG2"));
        //_JBIG2_hint.PushBack(Obj.CreateName("Lossy"));

      pdftron.PDF.Image img = pdftron.PDF.Image.Create(Doc, bmp);//,
_JBIG2_hint);

     img.ExportAsPng("c:\\test_pdftron_2.png");
     bmp.Save("c:\\test_pdftron_3.png");
     Element element = Builder.CreateImage(img, new
Matrix2D(img.GetImageWidth(), 0, 0, img.GetImageHeight(), Left,
Bottom));
     Writer.WritePlacedElement(element);
  }

I don't use any pictures saved to disk; this is just debugging info.
The image called test_pdftron_1 and test_pdftron3 are OK, but
test_pdftron_2 looks like a low quality jpeg.
-------
A:

The problem is that at the point when you are embedding
System.Drawing.Bitmap in PDF, PDFNet assumes default compression to be
JPEG (in lossy mode).

To go around this you can use encoder 'hints' to choose different
compression scheme. In you code you use JBIG2 hint, however this
applies only is the image data you are embedding is 1BPP monochrome.
Instead you can choose 'Flate' compression which corresponds to
lossless compression used in PNG format. For example:

Obj encoder_hint = Obj.CreateName("Flate");
pdftron.PDF.Image img = pdftron.PDF.Image.Create(Doc, bmp,
encoder_hint);

Alternatively you can stick with JPEG compression but increase the
Quality parameter. For example:

Obj hint2 = Obj.CreateArray();
hint2.PushBack(Obj.CreateName("JPEG"));
hint2.PushBack(Obj.CreateName("Quality"));
hint2.PushBack(Obj.CreateNumber(100));
pdftron.PDF.Image img = pdftron.PDF.Image.Create(Doc, bmp, hint2);

There is an error in the above definition of 'Flate' encoder hint. The
proper format is:

Obj encoder_hint = Obj.CreateArray("Flate");
encoder_hint.PushBack(Obj.CreateName("Flate"));

pdftron.PDF.Image img = pdftron.PDF.Image.Create(doc, bmp,
encoder_hint);