Sign in Join
Wiki copytemporary

BGRABitmap tutorial 2/es: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-[[BGRABitmap tutorial/es|**Home**]] | [[BGRABitmap tutorial 1/es|**Tutorial 1**]] | **Tutorial 2** | [[BGRABitmap tutorial 3/es|**Tutorial 3**]] | [[BGRABitmap tutorial 4/es|**Tutorial 4**]] | [[BGRABitmap tutorial 5/es|**Tutorial 5**]] | [[BGRABitmap tutorial 6/es|**Tutorial 6**]] | [[BGRABitmap tutorial 7/es|**Tutorial 7**]] | [[BGRABitmap tutorial 8/es|**Tutorial 8**]] | [ **Tutorial 9**](</index.php?title=BGRABitmap_tutorial_9/es&action=edit&redlink=1> "BGRABitmap tutorial 9/es \(page does not exist\)") | [[BGRABitmap tutorial 10/es|**Tutorial 10**]] | [[BGRABitmap tutorial 11/es|**Tutorial 11**]] | [[BGRABitmap tutorial 12/es|**Tutorial 12**]] | [Edit](<http://wiki.lazarus.freepascal.org/index.php?title=Template:BGRABitmap_tutorial_index/es&action=edit>)
2-
3-Esta tutoría muestra como cargar una imágen y dibujarla en una forma.
4-
5-## Contents
6-
7- * 1 Crear un nuevo proyecto
8- * 2 Carga el bitmap
9- * 3 Dibuja el bitmap
10- * 4 Código
11- * 5 Ejecuta el programa
12- * 6 Centrar la imágen
13- * 7 Estirar la imágen
1+Esta tutoría muestra como cargar una imágen y dibujarla en una forma.
142
153### Crear un nuevo proyecto
164
175Crea un nuevo proyecto y agrega referencias a [[BGRABitmap]] de la misma forma que se explica en [[BGRABitmap tutorial/es|la primer tutoría.]]
186
197### Carga el bitmap
208
21-Copia una imagen al directorio de tu proyecto. Supongamos que su nombre es _image.png_.
9+Copia una imagen al directorio de tu proyecto. Supongamos que su nombre es *image.png*.
2210
23-Agrega una variable privada a la forma principal para guardar la imágen:
24-```
25-TForm1 = class(TForm)
26- private
27- { private declarations }
28- image: TBGRABitmap;
29- public
30- { public declarations }
31- end;
32-```
11+Agrega una variable privada a la forma principal para guardar la imágen:
3312
34-Carga la imágen cuando la forma es creada. Para hacer esto haz doble clic en la forma, un procedimiento debería aparecer en el editor de código. Agrega la instrucción de cargado :
13+``` pascal
14+ TForm1 = class(TForm)
15+ private
16+ { private declarations }
17+ image: TBGRABitmap;
18+ public
19+ { public declarations }
20+ end;
3521```
22+
23+Carga la imágen cuando la forma es creada. Para hacer esto haz doble clic en la forma, un procedimiento debería aparecer en el editor de código. Agrega la instrucción de cargado :
24+
25+``` pascal
3626procedure TForm1.FormCreate(Sender: TObject);
37- begin
38- image := TBGRABitmap.Create('image.png');
39- end;
27+begin
28+ image := TBGRABitmap.Create('image.png');
29+end;
4030```
4131
4232### Dibuja el bitmap
4333
44-Añade un manejador OnPaint. Para hacer esto, selecciona la forma principal, luego ve al inspector de objetos, en la pestaña de eventos y haz doble clic en la linea OnPaint. Luego, agrega el código de dibujo :
45-```
34+Añade un manejador OnPaint. Para hacer esto, selecciona la forma principal, luego ve al inspector de objetos, en la pestaña de eventos y haz doble clic en la linea OnPaint. Luego, agrega el código de dibujo :
35+
36+``` pascal
4637procedure TForm1.FormPaint(Sender: TObject);
47- begin
48- image.Draw(Canvas,0,0,True);
49- end;
38+begin
39+ image.Draw(Canvas,0,0,True);
40+end;
5041```
5142
52-Fijate que el último parámetro está establecido en 'True' (verdadero) que sinifica opaco. Si quieres tomar los píxeles transparentes en cuenta, codificados en el canal alpha, debes usar 'False'. Pero puede ser lento usar dibujo transparente en un 'canvas' (papel) estándar, entonces si no es necesario usa dibujo opaco solamente.
43+Fijate que el último parámetro está establecido en 'True' (verdadero) que sinifica opaco. Si quieres tomar los píxeles transparentes en cuenta, codificados en el canal alpha, debes usar 'False'. Pero puede ser lento usar dibujo transparente en un 'canvas' (papel) estándar, entonces si no es necesario usa dibujo opaco solamente.
5344
5445### Código
5546
56-Finalmente deberías obtener algo como esto :
57-```
47+Finalmente deberías obtener algo como esto :
48+
49+``` pascal
5850unit UMain;
59-
60- {$mode objfpc}{$H+}
61-
62- interface
63-
64- uses
65- Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
66- BGRABitmap, BGRABitmapTypes;
67-
68- type
69- { TForm1 }
70-
71- TForm1 = class(TForm)
72- procedure FormCreate(Sender: TObject);
73- procedure FormPaint(Sender: TObject);
74- private
75- { private declarations }
76- image: TBGRABitmap;
77- public
78- { public declarations }
79- end;
80-
81- var
82- Form1: TForm1;
83-
84- implementation
85-
86- { TForm1 }
87-
88- procedure TForm1.FormCreate(Sender: TObject);
89- begin
90- image := TBGRABitmap.Create('image.png');
91- end;
92-
93- procedure TForm1.FormPaint(Sender: TObject);
94- begin
95- image.Draw(Canvas,0,0,True);
96- end;
97-
98- initialization
99- {$I UMain.lrs}
100-
101- end.
51+
52+{$mode objfpc}{$H+}
53+
54+interface
55+
56+uses
57+ Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
58+ BGRABitmap, BGRABitmapTypes;
59+
60+type
61+ { TForm1 }
62+
63+ TForm1 = class(TForm)
64+ procedure FormCreate(Sender: TObject);
65+ procedure FormPaint(Sender: TObject);
66+ private
67+ { private declarations }
68+ image: TBGRABitmap;
69+ public
70+ { public declarations }
71+ end;
72+
73+var
74+ Form1: TForm1;
75+
76+implementation
77+
78+{ TForm1 }
79+
80+procedure TForm1.FormCreate(Sender: TObject);
81+begin
82+ image := TBGRABitmap.Create('image.png');
83+end;
84+
85+procedure TForm1.FormPaint(Sender: TObject);
86+begin
87+ image.Draw(Canvas,0,0,True);
88+end;
89+
90+initialization
91+ {$I UMain.lrs}
92+
93+end.
10294```
10395
10496### Ejecuta el programa
10597
106-Deberías ver una forma con una imágen dibujada en ella en la esquina superior-izquierda.
98+Deberías ver una forma con una imágen dibujada en ella en la esquina superior-izquierda.
10799
108-[![BGRATutorial2.png](/wiki-images/d/db/BGRATutorial2.png)](</File:BGRATutorial2.png>)
100+![](/wiki-images/d/db/BGRATutorial2.png)
109101
110102### Centrar la imágen
111103
112-Quizás quieras centrar la imágen en la forma. Para hacer esto, modifica el procedimiento FormPaint :
113-```
104+Quizás quieras centrar la imágen en la forma. Para hacer esto, modifica el procedimiento FormPaint :
105+
106+``` pascal
114107procedure TForm1.FormPaint(Sender: TObject);
115- var ImagePos: TPoint;
116- begin
117- ImagePos := Point( (ClientWidth - Image.Width) div 2,
118- (ClientHeight - Image.Height) div 2 );
119-
120- // test de posición negativa
121- if ImagePos.X < 0 then ImagePos.X := 0;
122- if ImagePos.Y < 0 then ImagePos.Y := 0;
123-
124- image.Draw(Canvas,ImagePos.X,ImagePos.Y,True);
125- end;
108+var ImagePos: TPoint;
109+begin
110+ ImagePos := Point( (ClientWidth - Image.Width) div 2,
111+ (ClientHeight - Image.Height) div 2 );
112+
113+ // test de posición negativa
114+ if ImagePos.X < 0 then ImagePos.X := 0;
115+ if ImagePos.Y < 0 then ImagePos.Y := 0;
116+
117+ image.Draw(Canvas,ImagePos.X,ImagePos.Y,True);
118+end;
126119```
127120
128-Para computar la posición, necesitamos calcular el espacio entre la imágen y el borde izquierdo (coordenada X) y el espacio entre la imágen y el borde superior (coordenada Y). La expresion ClientWidth - Image.Width regresa el espacio horizontal disponible, y si lo dividimos por dos obtenemos el margen izquierdo.
121+Para computar la posición, necesitamos calcular el espacio entre la imágen y el borde izquierdo (coordenada X) y el espacio entre la imágen y el borde superior (coordenada Y). La expresion ClientWidth - Image.Width regresa el espacio horizontal disponible, y si lo dividimos por dos obtenemos el margen izquierdo.
129122
130-El resultado puede ser negativo si la imágen es mas grande que el ancho del cliente. En este caso, el margen es establecido como cero.
123+El resultado puede ser negativo si la imágen es mas grande que el ancho del cliente. En este caso, el margen es establecido como cero.
131124
132-Puedes ejecutar el programa y ver si funciona. Fijate que sucede si removes el test de posición negativa.
125+Puedes ejecutar el programa y ver si funciona. Fijate que sucede si removes el test de posición negativa.
133126
134127### Estirar la imágen
135128
136-Para estirar la imágen, necesitamos crear una imágen temporalmente estirada :
137-```
129+Para estirar la imágen, necesitamos crear una imágen temporalmente estirada :
130+
131+``` pascal
138132procedure TForm1.FormPaint(Sender: TObject);
139- var stretched: TBGRABitmap;
140- begin
141- stretched := image.Resample(ClientWidth, ClientHeight) as TBGRABitmap;
142- stretched.Draw(Canvas,0,0,True);
143- stretched.Free;
144- end;
133+var stretched: TBGRABitmap;
134+begin
135+ stretched := image.Resample(ClientWidth, ClientHeight) as TBGRABitmap;
136+ stretched.Draw(Canvas,0,0,True);
137+ stretched.Free;
138+end;
145139```
146140
147-Por defecto, esto usa el estiramiento fino, pero puedes precisar si quieres usar el estiramiento simple (mas rápido) :
148-```
141+Por defecto, esto usa el estiramiento fino, pero puedes precisar si quieres usar el estiramiento simple (mas rápido) :
142+
143+``` pascal
149144stretched := image.Resample(ClientWidth, ClientHeight, rmSimpleStretch) as TBGRABitmap;
150145```
151146
152-[[BGRABitmap tutorial 1/es|Primer tutoría]] | [[BGRABitmap tutorial 3/es|Siguiente tutoría (dibujando con el ratón)]]
147+[[BGRABitmap tutorial 1/es|Primer tutoría]] \| [[BGRABitmap tutorial 3/es|Siguiente tutoría (dibujando con el ratón)]]
153148
154149---
155-*From the Free Pascal wiki, page "BGRABitmap tutorial 2/es", as the Internet Archive kept it on 2025-05-16. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
150+*From the Free Pascal wiki, page "BGRABitmap tutorial 2/es", as it stood on 2020-02-10 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
151+Category: Castellano
152+Category: Español

Back to history