Last Updated:
31 Jan 2019 11:16
by ADMIN
FIX. RadPdfViewer - incorrect page export to an image with aspect ratio less than 1
How to reproduce:
float ratio = .5f;
private void radButton1_Click(object sender, EventArgs e)
{
float ratio = .5f;
this.radPdfViewer1.ExportPage(1, @"..\..\img.jpeg", ratio, true, ImageFormat.Png);
}
Workaround: change the resolution of the document after exporting it with a ratio = 1
private void radButton1_Click(object sender, EventArgs e)
{
float ratio = .5f;
Bitmap bmp = this.radPdfViewer1.ExportPage(1, 1, true, ImageFormat.Png);
Bitmap resizedImage = this.ResizeImage(bmp, (int)(bmp.Width * ratio), (int)(bmp.Height * ratio));
resizedImage.Save(@"..\..\img2.jpeg");
}
public Bitmap ResizeImage(Image image, int width, int height)
{
Rectangle destRect = new Rectangle(0, 0, width, height);
Bitmap destImage = new Bitmap(width, height);
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (var graphics = Graphics.FromImage(destImage))
{
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (var wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
}
}
return destImage;
}