In the latest build 2.0 beta2 the images that you add to a page will be rendered in low quality jpeg format.
This doesn't look very pretty when you want to print high quality images.
The cause of the low quality images is that the pdfImageReference constructor writes out the image to a memorystream using the default JPEG settings.
[old code: Class pdfImageReference line 79]
myImage.Save(outStream,System.Drawing.Imaging.ImageFormat.Jpeg);
[/old code]
The solution is to configure the jpeg generator to write high quality jpeg:
[new code]
myImage.Save(outStream, FindCodec("jpg"), CreateEncodingParameters(new EncoderParameter(Encoder.Quality, 100L)) );
[/new code]
This will output much nicer images in the PDF!
To use the new code you will need to helper functions:
[code]
/// <summary>
/// Find an image codec using the image extension
/// </summary>
/// <param name="fileExtension">an image extension such as jpg, png, gif, bmp, tif</param>
private ImageCodecInfo FindCodec(string fileExtension)
{
foreach(ImageCodecInfo info in ImageCodecInfo.GetImageEncoders())
{
if(info.FilenameExtension.ToLower().IndexOf(fileExtension.ToLower()) == -1) continue;
return info;
}
return null;
}
/// <summary>
/// Return a collection of EncodingParameters
/// </summary>
private static EncoderParameters CreateEncodingParameters(EncoderParameter parameter)
{
EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = parameter;
return encoderParameters;
}
[/code]
Please include this update in the source code of sharppdf. If you want me to send a patch file, let me know.
regards and thanks for the nice tool,
Mathieu van Loon