Transformer un System.Drawing.Graphics en Bitmap/Image

Résolu
Le_proprio_de_mykeyes Messages postés 60 Date d'inscription mardi 26 juillet 2005 Statut Membre Dernière intervention 16 avril 2006 - 2 févr. 2006 à 03:16
thr_dreamer_57 Messages postés 44 Date d'inscription lundi 27 juin 2005 Statut Membre Dernière intervention 3 novembre 2008 - 30 avril 2007 à 02:10
Bonjour, je me suis créé une application de sudoku (pour l'instant juste disponible sur http://cyberquebec.ca/mykeys mais bientot disponible sur Codes-sources) et je travaille avec la classe System.Drawing.Graphics pour imprimer mais je me demandais si il y avait un moyen de transformer en Bitmap (juste de sauvegarder en png)? j'ai essayé en vain de transférer dans un PictureBox mais ca refusait de sauvegarder. Voici un bout de code:
private void docToPrint_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e){
System.Drawing.Font printFont = new Font("Arial", 20, FontStyle.Regular);
e.Graphics.DrawString("Fait par Mykeys Sudoku",printFont,new SolidBrush(Color.Gray),100,200);
e.Graphics.DrawString("http://cyberquebec.ca/mykeys",printFont,new SolidBrush(Color.Gray),100,400);
e.Graphics.DrawString("David L.Pratte",printFont,new SolidBrush(Color.Gray),100,600);
e.Graphics.DrawLine(new Pen(Color.Black,3),40,40,820,40);
e.Graphics.DrawLine(new Pen(Color.Black,3),40,40,40,820);
e.Graphics.DrawLine(new Pen(Color.Black,3),40,820,820,820);
e.Graphics.DrawLine(new Pen(Color.Black,3),820,40,820,820);

e.Graphics.DrawLine(new Pen(Color.Black,3),300,40,300,820);
e.Graphics.DrawLine(new Pen(Color.Black,3),560,40,560,820);

e.Graphics.DrawLine(new Pen(Color.Black,3),40,300,820,300);
e.Graphics.DrawLine(new Pen(Color.Black,3),40,560,820,560);

//Horizontal
e.Graphics.DrawLine(new Pen(Color.Black,1),126,40,126,820);
e.Graphics.DrawLine(new Pen(Color.Black,1),212,40,212,820);

e.Graphics.DrawLine(new Pen(Color.Black,1),386,40,386,820);
e.Graphics.DrawLine(new Pen(Color.Black,1),472,40,472,820);

e.Graphics.DrawLine(new Pen(Color.Black,1),646,40,646,820);
e.Graphics.DrawLine(new Pen(Color.Black,1),732,40,732,820);

//Vertical
e.Graphics.DrawLine(new Pen(Color.Black,1),40,126,820,126);
e.Graphics.DrawLine(new Pen(Color.Black,1),40,212,820,212);

e.Graphics.DrawLine(new Pen(Color.Black,1),40,386,820,386);
e.Graphics.DrawLine(new Pen(Color.Black,1),40,472,820,472);

e.Graphics.DrawLine(new Pen(Color.Black,1),40,646,820,646);
e.Graphics.DrawLine(new Pen(Color.Black,1),40,732,820,732);

e.Graphics.DrawString("Fait par Mykeys Sudoku",printFont,new SolidBrush(Color.Gray),100,850);
e.Graphics.DrawString("http://cyberquebec.ca/mykeys",printFont,new SolidBrush(Color.Gray),100,910);
e.Graphics.DrawString("David L.Pratte",printFont,new SolidBrush(Color.Gray),100,970);


}Merci de m'aider  David
A voir également:

3 réponses

Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
2 févr. 2006 à 06:30
Salut, je ne suis pas sûr de comprendre ce que tu veux.

Pour dessiner dans un bitmap :

Bitmap bmp = new Bitmap( 640, 480 );
using ( Graphics g = Graphics.FromImage( bmp ) )
{
// Draw..
}
bmp.Save( "C:\\image.png", System.Drawing.Imaging.ImageFormat.Png );
3
Rejoignez-nous