
21/11/2007, 18:41
|
 | | | Fecha de Ingreso: junio-2006 Ubicación: Colombiano viviendo en Es
Mensajes: 73
Antigüedad: 18 años, 9 meses Puntos: 0 | |
Re: Seleccionar trozos de ina imagen en eun PictureBox y poderlos guardar y dejar mar Hola!!!
Al final lo he intentado de 20000 formas diferentes, y me sigue pasando básicamente lo mismo, la imagen que me pone en el pictureBox es de una zona diferente a la que yo he seleccionado. Intenté con lo de RectangleToClient, pero sólo me sirvió en parte. Ahora mismo, lo estoy intentando hacer sobre un pictureBox, que está dentro de una tabPage, estos dentro de un formulario. Adjunto el código y un video a ver alguien si me puede ayudar: http://www.megaupload.com/?d=IN3T0YC0 o http://rapidshare.com/files/71384291/video.rar.html (660KB)
Código:
private bool seleccionar = false;
private Rectangle RectanguloSeleccion;
private Point PuntoInicio;
private Point PuntoFin;
private int anchoSeleccion;
private int alturaSeleccion;
private void MouseDown_PictureBox(object sender, MouseEventArgs e)
{ this.Click_Raton(sender,e);
}
private void MouseUp_PictureBox(object sender, MouseEventArgs e)
{ this.Levantar_Raton(sender,e);
}
private void MouseMove_PictureBox(object sender, MouseEventArgs e)
{ this.Mover_Raton(sender,e);
}
private void Click_Raton(object sender,MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
seleccionar = true;
}
Control control = (Control)sender;
PuntoInicio = control.PointToScreen(new Point(e.X, e.Y));
}
private void Mover_Raton(object sender,MouseEventArgs e)
{
if (seleccionar)
{
ControlPaint.DrawReversibleFrame(RectanguloSeleccion,Color.Silver, FrameStyle.Dashed);
PuntoFin = ((Control)sender).PointToScreen(new Point(e.X, e.Y));
anchoSeleccion = PuntoFin.X - PuntoInicio.X;
alturaSeleccion = PuntoFin.Y - PuntoInicio.Y;
RectanguloSeleccion = new Rectangle(PuntoInicio.X, PuntoInicio.Y, anchoSeleccion, alturaSeleccion);
ControlPaint.DrawReversibleFrame(RectanguloSeleccion,Color.Silver, FrameStyle.Dashed);
}
}
private void Levantar_Raton(object sender, MouseEventArgs e)
{
seleccionar = false;
ControlPaint.DrawReversibleFrame(RectanguloSeleccion,Color.Blue, FrameStyle.Thick);
Rectangle r1 = this.pictureBoxPrincipal.RectangleToClient(RectanguloSeleccion);
Bitmap imagenPequeña = new Bitmap(anchoSeleccion, alturaSeleccion, this.pictureBoxPrincipal.Image.PixelFormat);
Rectangle rectDest = new Rectangle(0, 0, anchoSeleccion, alturaSeleccion);
Graphics g = Graphics.FromImage(imagenPequeña);
g.DrawImage(this.pictureBoxPrincipal.Image, rectDest, r1, GraphicsUnit.Pixel);
g.Dispose();
PictureBox newPB = new PictureBox();
newPB.Image = imagenPequeña;
newPB.BorderStyle = BorderStyle.Fixed3D;
this.pictureBoxPrincipal.Controls.Add(newPB);
newPB.Location = new System.Drawing.Point(r1.X, r1.Y);
newPB.Size = new System.Drawing.Size(anchoSeleccion, alturaSeleccion);
newPB.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal;
}
Espero que alguien me pueda ayudar. Gracias y saludos!!!!
Última edición por kalixe985; 21/11/2007 a las 19:16 |