lolo818 wrote:
I remade a test, but without success, the original image is always lighter than the generated pdf.
The image included in the PDF file is not a JPEG image.
Your code snippet doesn't show where Pic1Resize comes from. I guess it's not loaded from a JPEG file (maybe it's originally loaded from a JPEG file, but modified later on).
If your code resizes the image: save that image as JPEG (specifying the image quality you need) and load it again. Then the PDF file will contain a JPEG compressed image (much smaller).
Saving to a memory stream and loading from that memory stream should do (no file I/O involved).
I tried this code:
Code:
XImage image = XImage.FromFile(@"C:\Users\thho\Desktop\$$$\$$$PDFsharp\PicResize\pic1.JPG");
gfx.DrawImage(image, 0, 0, image.PixelWidth * 2, image.PixelHeight * 2);
The resulting PDF file was 15 kiB in size (15,108 bytes) while your JPEG image has 15,700 bytes. PDF file is smaller here!
I include the PDF.
Calling "XImage.FromGdiPlusImage(Image.FromStream(stream))" should do the trick.
Or add a new "FromStream" to the XImage class:
Code:
/// <summary>
/// Creates an image from the specified stream.
/// </summary>
public static XImage FromStream(Stream stream)
{
return new XImage(stream);
}