[GDI+] DrawLine et Zoom

ZogStriP Messages postés 164 Date d'inscription dimanche 16 novembre 2003 Statut Modérateur Dernière intervention 5 juillet 2005 - 1 déc. 2004 à 20:45
ZogStriP Messages postés 164 Date d'inscription dimanche 16 novembre 2003 Statut Modérateur Dernière intervention 5 juillet 2005 - 17 déc. 2004 à 18:41
Je suis en train de faire un logiciel qui ressemble un peu à Paint (surtout pour l'édition au pixel prés et pour le zoom)

Malheureusement je n'arrive pas à faire le zoom...
Est ce que quelqu'un pourrais m'aider ?

Merci

Voilà mon code :

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Tests
{
/// <summary>
/// Description résumée de Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();

//
// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
//
}

/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
// 
// pictureBox1
// 
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(64, 40);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(405, 405);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);
this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
// 
// button1
// 
this.button1.Location = new System.Drawing.Point(480, 88);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(40, 56);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// label1
// 
this.label1.Location = new System.Drawing.Point(160, 472);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 40);
this.label1.TabIndex = 2;
this.label1.Text = "label1";
// 
// label2
// 
this.label2.Location = new System.Drawing.Point(264, 464);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 64);
this.label2.TabIndex = 3;
this.label2.Text = "label2";
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(592, 542);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
}

bool bWrite = false;
Bitmap Carte = new Bitmap(200,200);
Point oldPos = new Point();
int Zoom = 1;double X 0,Y 0;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
bWrite = true;
oldPos = new Point(e.X,e.Y);
}

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
X = Math.Round((double) (((1f * e.X) / ((float) Zoom))), 0);
Y = Math.Round((double) (((1f * e.Y) / ((float) Zoom))), 0);
if((X > -1) & (Y > -1) & (X <= 200) & (Y <= 200))
{
this.label1.Text = X.ToString();
this.label2.Text = Y.ToString();
}
if(bWrite)
{
Graphics g = null;
g = Graphics.FromImage(Carte);
Pen Stylo = new Pen(System.Drawing.Color.Red, 1);
g.DrawLine(Stylo,oldPos,new Point(e.X,e.Y));
g.Dispose();
this.pictureBox1.Invalidate();
oldPos = new Point(e.X,e.Y);
}
}

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
bWrite = false;
}

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage (Carte, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel);
}

private void button1_Click(object sender, System.EventArgs e)
{
// Permet de faire le zoom ;)
Zoom++;
Bitmap tmpCarte = new Bitmap(400,400);
tmpCarte = ZoomIt(2);
Carte = new Bitmap(400,400);
Carte = tmpCarte;
}

public Bitmap ZoomIt(int Zoom)
{
Bitmap tmpBitmap = new Bitmap(200 * Zoom, 200 * Zoom);
Graphics Dessinateur = Graphics.FromImage(tmpBitmap);
Color Couleur = new Color();
for (int i = 0; i < 200; i++)
{
for (int j = 0; j < 200; j++)
{
Couleur = Color.FromArgb(Carte.GetPixel(i,j).ToArgb());
Dessinateur.FillRectangle(new SolidBrush(Couleur), (int) (i * Zoom), (int) (j * Zoom), Zoom, Zoom);
}
}
Dessinateur.Dispose();
return tmpBitmap;
}
 

}
}



ZogStriP
IA pour : Incomplet de l'Ancéphale %-6
http://blog.developpeur.org/zogstrip/
8-) www.rubikscubor.fr.st 8-)

#define ThatTheQuestion ((bb) || !(bb))

3 réponses

ZogStriP Messages postés 164 Date d'inscription dimanche 16 novembre 2003 Statut Modérateur Dernière intervention 5 juillet 2005 1
1 déc. 2004 à 21:01
En relisant mon post, je me suis apercus que je n'ai pas dis ce que je voulais...

En fait je voudrais qu'une fois que l'on a zoomé, au lieu de dessiner une ligne de largeur 1, on dessine une ligne de largeur 2...

Merci

ZogStriP
IA pour : Incomplet de l'Ancéphale %-6
http://blog.developpeur.org/zogstrip/
8-) www.rubikscubor.fr.st 8-)

#define ThatTheQuestion ((bb) || !(bb))
0
YASminelover Messages postés 4 Date d'inscription samedi 3 janvier 2004 Statut Membre Dernière intervention 20 décembre 2004
17 déc. 2004 à 16:21
Dans ton MouseMouve,

Pen Stylo = new Pen(System.Drawing.Color.Red, 1);

tu déclare ton "Pen" avec un largeur de 1.
tu a juste a changé en mettant par exemple ta valeur de Zoom:

Pen Stylo = new Pen(System.Drawing.Color.Red, Zoom);
0
ZogStriP Messages postés 164 Date d'inscription dimanche 16 novembre 2003 Statut Modérateur Dernière intervention 5 juillet 2005 1
17 déc. 2004 à 18:41
C'est gentil pour la réponse, mais le problème est qu'en fait, ce que tu me dis ne fais que donner une LARGEUR et non une LARGEUR ET LONGUEUR au pinceaux, donc ça fait seulement des lignes plus larges...

Mais je penses que pour résoudre le problème il faudrais utiliser la fonction DrawRectangle... mais ne seulement mettre à jour que ce qui à été modifié, et non redessiner à chaque fois les 200*200 (*Zoom) pixels..

Si tu sais comment faire ?

Merci

ZogStriP
IA pour : Incomplet de l'Ancéphale %-6
http://blog.developpeur.org/zogstrip/
8-) www.rubikscubor.fr.st 8-)

#define ThatTheQuestion ((bb) || !(bb))
0
Rejoignez-nous