Impression d'image, problème de dimension
Bonjour
J'essaie d'imprimer une image (application winForm, .NET 2.0)
Ma fonction PrintPage
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
SizeF newSize = (SizeF)formMap.pMapImage.Image.Size;
float xRatio = (float)e.MarginBounds.Width / (float)newSize.Width;
float yRatio = (float)e.MarginBounds.Height / (float)newSize.Height;
float ratio = Math.Min(xRatio, yRatio);
newSize.Width *= ratio;
newSize.Height *= ratio;
Bitmap bmp = new Bitmap(formMap.pMapImage.Image, new Size((int)newSize.Width, (int)newSize.Height));
e.Graphics.DrawImage(Image.FromHbitmap(bmp.GetHbitmap()), new Point(0, 0));
} |
Ca fonctionne pas trop mal mais j'ai quelques problèmes avec le redimensionnement.
Au moment d'entrer dans ma fonction j'ai les valeurs suivantes :
dimensions de mon image : 1276 x 893
e.MarginBounds : x : 100, y : 100, width : 627, height : 438
à la fin l'image redimensionnée (variable bmp) à une taille de 627 x 438, donc à priori tout devrait être ok. Mais non, sur ma feuille, mon image n'occupe pas toute la largeur (après déduction des marges évidemment).