![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Buscar | Temas de Hoy | Marcar Foros Como Leídos |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
|
|
#1
|
||||
|
||||
|
Hola NEG1414.
Usando un arreglo podes hacer: Código:
...
void copiar(TRect R)
{
for(int x = R.left; x<R.right; x++)
for(int y= R.top; y<R.Bottom; y++)
Fondo[x][y] = Form1->Canvas->Pixels[x][y];
}
void pegar(TRect R, int PX, int PY)
{
for(int x = R.left; x<R.right; x++)
for(int y= R.top; y<R.Bottom; y++)
Form1->Canvas->Pixels[PX+x][PY+y] = Fondo[x][y];
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Canvas->TextOutA(0,0,"PRUEBA");
// salvar el área de 'PRUEBA'
copiar(Rect(0, 0, Canvas->TextWidth("PRUEBA"),
Canvas->TextHeight("PRUEBA")));
// escribir algo sobre 'PRUEBA'
Canvas->TextOutA(0 0, "XX");
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// restaurar el área
pegar(Rect(0,0,Canvas->TextWidth("PRUEBA"),
Canvas->TextHeight("PRUEBA")), 0, 0);
}
Header: Código:
class TForm1 : public TForm
{
__published:
TImage *Image1;
TLabel *Label1; // sobre la imágen
TButton *Button1;
TButton *Button2;
...
void __fastcall Button1Click(TObject *Sender);
private:
Graphics::TBitmap *FBM;
void __fastcall GetWndArea(int x1, int y1, int x2, int y2);
...
Código:
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
FBM = new Graphics::TBitmap;
randomize();
}
void __fastcall TForm1::GetWndArea(int x1, int y1, int x2, int y2)
{
FBM->Width = x2-x1;
FBM->Height= y2-y1;
TRect R = Rect(0,0,FBM->Width,FBM->Height);
FBM->Canvas->CopyRect(R, Canvas, R);
}
void Modificar(Graphics::TBitmap *B)
{
int x,y;
for(y=0; y < B->Height; y++) {
for(x=0; x < B->Width; x++)
B->Canvas->Pixels[x][y] = (TColor)(rand()% 0xFFFFFFF);
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// salvar el área de la imagen
GetWndArea(0, 0, Image1->Width,Image1->Height);
// modificarla
Modificar(Image1->Picture->Bitmap);
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// restaurar el área
Canvas->Draw(0, 0, FBM);
}
![]()
__________________
Daniel Didriksen Guía de estilo - Uso de las etiquetas - La otra guía de estilo .... |
|
#2
|
|||
|
|||
|
Gracias por por contestame...
En pricipio tomaria la el primer metodo que has indicado para guardar y mostrar una zona de pantalla.. pero me surge un problema... La captura de "trozo" pantalla y posterior "reposicion" se realiza dentro de un componente visual que he creado de la forma: Código:
class PACKAGE Grafica : public TCustomControl
{
...........
..........
podria refrescar el componente completamente pero conlleva una serie de operaciones que haria que el refres no fuese fluido y se notara.. para ello prefiero solo "repintar" pixel a pixel la zona donde estaba el panel (que antes habria guardado) de la forma que mostre al inicio del Post... Al aceder al Repintado desde el componente mediante Código:
Form1->Canvas->Pixels[PX+x][PY+y] = Fondo[x][y]; (el segundo metodo al incluir un TImage en la operacion me complica el tema considerablemente..) Puedes indicarme como adaptar el primer metodo a mi caso...Gracias Otra Vez |
|
#3
|
||||
|
||||
|
Cita:
Creo que el ejemplo no fué suficientemente claro , no es necesario incluir un TImage para capturar el área del formulario. Tal vez de este modo resulte mas claro: Código:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
FBM = new Graphics::TBitmap;
}
// Guardar área
void __fastcall TForm1::GetWndArea(int x1, int y1, int x2, int y2)
{
FBM->Width = x2-x1;
FBM->Height= y2-y1;
TRect R = Rect(0,0,FBM->Width,FBM->Height);
FBM->Canvas->CopyRect(R, Canvas, R);
}
// Poner algo en el form, esperarar 1 seg y borrar el área
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char *t1="TEXTO 1",*t2="TEXTO 2";
Canvas->Ellipse(0, 0, 300, 100);
Canvas->TextOut(120, 30, t1);
Canvas->TextOut(120, 30 + Canvas->TextHeight(t1),t2);
Canvas->Brush->Style = bsClear;
GetWndArea(0,0,305,105);
Sleep(1000);
Canvas->Brush->Color = Color;
Canvas->Brush->Style = bsSolid;
Canvas->FillRect(Rect(0,0,FBM->Width,FBM->Height));
}
// restaurar el área borrada
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Canvas->Draw(0, 0, FBM);
}
![]()
__________________
Daniel Didriksen Guía de estilo - Uso de las etiquetas - La otra guía de estilo .... |
|
#4
|
|||
|
|||
|
Muchas gracias por tu tiempo ecfisa voy a probar y te cuento....
|
|
#5
|
||||
|
||||
|
Hola NEG1414.
Quien dice 30 dice 31... , yo me refería a implementar algo parecido a esto:Código:
...
class PACKAGE MiControl : public TCustomControl
{
private:
Graphics::TBitmap *FArea;
TControlCanvas *FCtrlCanvas;
//...
public:
__fastcall MiControl(TComponent *Owner) : TCustomControl(Owner)
{
FArea = new Graphics::TBitmap;
FCtrlCanvas = new TControlCanvas;
FCtrlCanvas->Control = this;
};
__fastcall ~MiControl()
{
delete FArea;
delete FCtrlCanvas;
}
void __fastcall LoadArea(void)
{
FArea->Width = Left + Width;
FArea->Height = Top + Height;
TRect R = Rect(0, 0, FArea->Width, FArea->Height);
FArea->Canvas->CopyRect(R, Canvas, R);
};
__property TControlCanvas *Canvas = { read = FCtrlCanvas, write = FCtrlCanvas};
__property Graphics::TBitmap *Area = { read = FArea, write = FArea };
};
MiControl *mc;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
mc = new MiControl(this);
}
// Crear y mostrar
void __fastcall TForm1::btnCreateClick(TObject *Sender)
{
mc->Left = 0;
mc->Top = 0;
mc->Width = 250;
mc->Height = 300;
mc->Parent = this;
// Dibujar algo
mc->Canvas->Ellipse(0,0,mc->Width-10,mc->Height-40);
// Guardar área
mc->LoadArea();
}
// borrar área
void __fastcall TForm1::btnClearClick(TObject *Sender)
{
mc->Canvas->Brush->Color = Color;
mc->Canvas->FillRect(Rect(0,0,mc->Width,mc->Height));
}
// Restaurar área
void __fastcall TForm1::btnRestoreClick(TObject *Sender)
{
mc->Canvas->Draw(0,0,mc->Area);
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
delete mc;
}
![]()
__________________
Daniel Didriksen Guía de estilo - Uso de las etiquetas - La otra guía de estilo .... |
|
#6
|
|||
|
|||
|
Buenas..
Siento ser tan pesado pero no doy hecho que se reponga la imagen del trozo de componente que deseo... la verdad es que dibuja el area totalmente blanca... Dado que la todas las operaciones las hago desde el propio componente (por si sirve de algo lo que se va ha visiualizar en el componente lo dibujo mediante el metodo paint() usandola la propiedad canvas) lo he dadptado asi: Código:
class PACKAGE TGrafica : public TCustomControl
{
__published: // IDE-managed Components
TPanel *PanelInf;
Graphics::TBitmap *AreaPanelInf;
TControlCanvas *FCtrlCanvas;
int PPx; //Posicion X esquina superior Derecha Panel Informacion
int PPy; //Posicion Y esquina superior Derecha Panel Informacion
.................
void TGrafica::MostrarPanelDatos()
{
AreaPanelInf->Width = 16;
AreaPanelInf->Height = 10;
TRect R = Rect(PPx,PPy,AreaPanelInf->Width,AreaPanelInf->Height);
AreaPanelInf->Canvas->CopyRect(R, Canvas, R);
//Creo y visualizo Panel Informacion
PanelInf = new TPanel (this);
PanelInf->Parent = this;
PanelInf->Height = 10;
PanelInf->Width = 16;
PanelInf->Left = PPx;
PanelInf->Top = PPy;
PanelInf->Visible = true;
Application->ProcessMessages();
}
//---------------------------------------------------------------------------
//Restaura que ocupada el Panel Informativo
void TGrafica::RestaurAreaPanel()
{
PanelInf->Visible = false;
this->Canvas->Draw(PPx,PPy,AreaPanelInf);
Application->ProcessMessages();
}
|
|
#7
|
|||
|
|||
|
Buenas..
Retomo el tema adjuntando una pequeña aplicacion que intenta explicar graficamente mi problema... https://app.box.com/s/6gvqol66wahyhuk1negu He llegado a la conclusion de que uasando el codigo siguiente (gracias ecfisa): Código:
FArea->Width = Left + Width;
FArea->Height = Top + Height;
TRect R = Rect(0, 0, FArea->Width, FArea->Height);
FArea->Canvas->CopyRect(R, Canvas, R);
Dado que solo modifica areas afectadas por el evento paint().. no gano nada guardando y recuperando una pequeña area ya que el Procedimiento paint() regenera la imagen de todo el componente si o si.. Hay alguna manera de regenerar el area dibujada desde otro procedimiento diferente al Paint() Espero haberme explicado bien... Gracias. |
![]() |
| Herramientas | Buscar en Tema |
| Desplegado | |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| Dibujar Elipse y Parábola pixel a pixel | Deiv | Gráficos | 9 | 28-11-2016 10:19:41 |
| Como obtener el color de un pixel | ilichhernandez | Gráficos | 11 | 02-11-2006 15:40:00 |
| Guardar y recuperar | noipa | Varios | 3 | 07-02-2006 14:46:21 |
| pasar imagen pixel a pixel | gulder | Gráficos | 7 | 26-06-2005 02:10:45 |
| ¿ Cual es la mejor forma de implementar una Pizarra con Sockets? pixel a pixel ? | sase | Internet | 1 | 22-10-2003 16:23:50 |
|