Réponse acceptée !
"j'ai un picturebox et je lui attribue une image bitmap. ensuite je permet a l'utilisateur de redéssiné par dessus"
Tu dois dessiner avec le Graphics de l'image, utilise Graphic.FromImage pour le récupérer, ainsi tu dessinera directement sur l'image, pour voir les modifications tu dois invalider la PictureBox, PictureBox.Invalidate, et tu sauvegardes avec Picture.Image.Save.
public partial class Form1 : Form
{
private Bitmap bitmap = null;
private Graphics graphics = null;
private PictureBox pictureBox = null;
private Point startPoint = Point.Empty;
public Form1( )
{
InitializeComponent( );
bitmap = new Bitmap( "image.jpg" );
graphics = Graphics.FromImage( bitmap );
pictureBox = new PictureBox( );
pictureBox.Dock = DockStyle.Fill;
pictureBox.ContextMenu = new ContextMenu
(
new MenuItem[ ]
{
new MenuItem
(
"Save",
PictureBox_SaveFile
)
}
);
pictureBox.Image = bitmap;
pictureBox.MouseDown += PictureBox_MouseDown;
pictureBox.MouseMove += PictureBox_MouseMove;
this.Controls.Add( pictureBox );
}
private void PictureBox_SaveFile( object sd, EventArgs e )
{
SaveFileDialog saveFileDalog = new SaveFileDialog( );
if ( saveFileDalog.ShowDialog( ) == DialogResult.OK )
pictureBox.Image.Save( saveFileDalog.FileName );
}
private void PictureBox_MouseDown( object sd, MouseEventArgs e )
{
if ( e.Button == MouseButtons.Left )
startPoint = e.Location;
}
private void PictureBox_MouseMove( object sd, MouseEventArgs e )
{
if ( e.Button == MouseButtons.Left )
{
GraphicsPath path = new GraphicsPath( );
path.AddLine( startPoint, e.Location );
startPoint = e.Location;
graphics.DrawPath( Pens.Black, path );
pictureBox.Invalidate( pictureBox.ClientRectangle );
}
}
}
Mais à mon avis tu devrais te passer de la PictureBox et dessiner sur un backbuffer puis l'afficher sur la forme ou sur un contrôle via Graphics.DrawImage.