[c#] Aiuto disegnare rettangolo

lunedì 08 gennaio 2007 - 16.36

er tikre Profilo | Newbie

ragazzi non riesco a disegnare un rettangolo su un'immagine bmp posto la procedura qui sotto:
private void disegnaRettangolo(string nomeImg, string c, double larg, double alt)
{
int x1, y1, l, a;
string[] appo = new string[9];
appo = c.Split(' ');
x1 = Convert.ToInt32(appo[1]);
y1 = Convert.ToInt32(appo[2]);

l = Convert.ToInt32(larg);
a = Convert.ToInt32(alt);

Bitmap myBitmap = new Bitmap(nomeImg);
Graphics g = Graphics.FromImage(myBitmap);

System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
//System.Drawing.Graphics formGraphics;
//Point punto = new Point();
myPen.Width = 3;

g = this.CreateGraphics();
g.DrawRectangle(myPen, new Rectangle(x1, y1, l, a));
g.DrawImage(myBitmap, 1, 1);
//myBitmap.Save(nomeImg);
myPen.Dispose();
g.Dispose();

}

dove sbaglio??
www.expoline.it Cosa volete? qui lo troverete! il portale Anormale!!

maurosegato Profilo | Newbie

Ecco la soluzione...

private void disegnaRettangolo(string nomeImg, string c, double larg, double alt)
{
int x1, y1, l, a;
string[] appo = new string[9];
appo = c.Split(' ');
x1 = Convert.ToInt32(appo[1]);
y1 = Convert.ToInt32(appo[2]);

l = Convert.ToInt32(larg);
a = Convert.ToInt32(alt);

Bitmap myBitmap = new Bitmap(nomeImg);
Graphics g = Graphics.FromImage(myBitmap);

System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
//System.Drawing.Graphics formGraphics;
//Point punto = new Point();
myPen.Width = 3;

g.DrawRectangle(myPen, new Rectangle(x1, y1, l, a));
g.Dispose();

g = this.CreateGraphics();g.DrawImage(myBitmap, 1, 1);
//myBitmap.Save(nomeImg);
myPen.Dispose();
g.Dispose();

}

la chiamata a g.DrawRectangle(...) la richiamavi quando l'oggetto grafico era riferito al form e non alla bitmap..
ciao

Mauro Segato

er tikre Profilo | Newbie

Non mi funziona ......Aiuto non salva l'immagine .....

private void disegnaRettangolo(string nomeImg, string c, double larg, double alt)
{
int x1, y1, l, a;
string[] appo = new string[9];
appo = c.Split(' ');
x1 = Convert.ToInt32(appo[1]);
y1 = Convert.ToInt32(appo[2]);

l = Convert.ToInt32(larg);
a = Convert.ToInt32(alt);

Bitmap myBitmap = new Bitmap(nomeImg);
Graphics g = Graphics.FromImage(myBitmap);

System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);

g.DrawRectangle(myPen, new Rectangle(x1, y1, l, a));

g = this.CreateGraphics();
g.DrawImage(myBitmap, 1, 1);

myPen.Dispose();
g.Dispose();

}
www.expoline.it Cosa volete? qui lo troverete! il portale Anormale!!

er tikre Profilo | Newbie

in effetti ho risolto grazie bisognava salvarla!!!!
www.expoline.it Cosa volete? qui lo troverete! il portale Anormale!!
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5