bonjour je veux enregistrer un graphique créer dans une picturebox et merci d'avance
et comment affecter un picturebox a un autre qui plus petit sans perdre le graphique ??
Voilà ce que j'ai compris, c'est sur quoi j'ai travaillé
Bonjour, je veux enregistrer (save) un graphique créér. Que ce soit un graphique que tu as loader de ton ordinateur ou que tu as créer un logiciel de dessin et que ton picture box soit ton aperçu, le save se fera de la même facon.
Comment affecter un picture box disons (100 height x 100 width)
à un autre plus petit (50 height x 50 width)
Soit la moitié dans la largeur et l'hauteur.
Sans perdre le graphique, donc tu veux réduire ton image, mais qu'elle reste entière
Voilà le programme que je t'ai fait : tout est fonctionnel, ajuste-le à tes besoins.
Voici le code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PictureBoxSave
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnOuvrir_Click(object sender, EventArgs e)
{
// C'est une bonne habitude d'utiliser / au lieu de \\ pour les chemin d'accès
// Moins d'erreur, et portable sur plusieurs OS
pctGrand.Load("E:/Projets/Test/PictureBoxSave/Test.bmp");
if (pctGrand.Image != null)
{
btnReduire.Enabled = true;
btnSauvegrarder.Enabled = true;
}
else
txtInfo.Text = "L'image n'a pas pu être loader";
}
private void btnReduire_Click(object sender, EventArgs e)
{
Bitmap bmpOriginal = new Bitmap(pctGrand.Image, 150, 150);
pctPetit.Image = bmpOriginal;
}
private void btnSauvegrarder_Click(object sender, EventArgs e)
{
Bitmap bmpSave = new Bitmap(pctGrand.Image);
bmpSave.Save("E:/Projets/Test/PictureBoxSave/TestSave.bmp");
}
}
}
Voici le code du designeur si tu veux refaire le programme exactement comme le mien
namespace PictureBoxSave
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSauvegrarder = new System.Windows.Forms.Button();
this.btnReduire = new System.Windows.Forms.Button();
this.pctGrand = new System.Windows.Forms.PictureBox();
this.pctPetit = new System.Windows.Forms.PictureBox();
this.btnOuvrir = new System.Windows.Forms.Button();
this.txtInfo = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pctGrand)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pctPetit)).BeginInit();
this.SuspendLayout();
//
// btnSauvegrarder
//
this.btnSauvegrarder.Enabled = false;
this.btnSauvegrarder.Location = new System.Drawing.Point(330, 217);
this.btnSauvegrarder.Name = "btnSauvegrarder";
this.btnSauvegrarder.Size = new System.Drawing.Size(152, 43);
this.btnSauvegrarder.TabIndex = 0;
this.btnSauvegrarder.Text = "Sauvegarder";
this.btnSauvegrarder.UseVisualStyleBackColor = true;
this.btnSauvegrarder.Click += new System.EventHandler(this.btnSauvegrarder_Click);
//
// btnReduire
//
this.btnReduire.Enabled = false;
this.btnReduire.Location = new System.Drawing.Point(330, 269);
this.btnReduire.Name = "btnReduire";
this.btnReduire.Size = new System.Drawing.Size(152, 43);
this.btnReduire.TabIndex = 1;
this.btnReduire.Text = "Reduire";
this.btnReduire.UseVisualStyleBackColor = true;
this.btnReduire.Click += new System.EventHandler(this.btnReduire_Click);
//
// pctGrand
//
this.pctGrand.Location = new System.Drawing.Point(12, 12);
this.pctGrand.Name = "pctGrand";
this.pctGrand.Size = new System.Drawing.Size(300, 300);
this.pctGrand.TabIndex = 2;
this.pctGrand.TabStop = false;
//
// pctPetit
//
this.pctPetit.Location = new System.Drawing.Point(332, 12);
this.pctPetit.Name = "pctPetit";
this.pctPetit.Size = new System.Drawing.Size(150, 150);
this.pctPetit.TabIndex = 3;
this.pctPetit.TabStop = false;
//
// btnOuvrir
//
this.btnOuvrir.Location = new System.Drawing.Point(332, 168);
this.btnOuvrir.Name = "btnOuvrir";
this.btnOuvrir.Size = new System.Drawing.Size(152, 43);
this.btnOuvrir.TabIndex = 4;
this.btnOuvrir.Text = "Ouvrir une image";
this.btnOuvrir.UseVisualStyleBackColor = true;
this.btnOuvrir.Click += new System.EventHandler(this.btnOuvrir_Click);
//
// txtInfo
//
this.txtInfo.Location = new System.Drawing.Point(12, 326);
this.txtInfo.Name = "txtInfo";
this.txtInfo.Size = new System.Drawing.Size(470, 20);
this.txtInfo.TabIndex = 5;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(496, 358);
this.Controls.Add(this.txtInfo);
this.Controls.Add(this.btnOuvrir);
this.Controls.Add(this.pctPetit);
this.Controls.Add(this.pctGrand);
this.Controls.Add(this.btnReduire);
this.Controls.Add(this.btnSauvegrarder);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pctGrand)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pctPetit)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnSauvegrarder;
private System.Windows.Forms.Button btnReduire;
private System.Windows.Forms.PictureBox pctGrand;
private System.Windows.Forms.PictureBox pctPetit;
private System.Windows.Forms.Button btnOuvrir;
private System.Windows.Forms.TextBox txtInfo;
}
}
Si jamais ce n'était pas ce que tu voulais, écris-nous exactement ce que tu veux.
Pierre-Luc