BGRABitmap tutorial 12/es: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: BGRABitmap tutorial 12/es
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Esta tutoría muestra como usar funciones de texto. | |
| 2 | + | ||
| 3 | + | ### Crear un nuevo proyecto | |
| 4 | + | ||
| 5 | + | Crea un nuevo proyecto y añade referencia a [[BGRABitmap]], de la misma forma que en[[BGRABitmap tutorial/es|la primer tutoríal]]. | |
| 6 | + | ||
| 7 | + | ### Texto simple | |
| 8 | + | ||
| 9 | + | Puedes dibujar un texto simple como este : | |
| 10 | + | ||
| 11 | + | ``` pascal | |
| 12 | + | procedure TForm1.FormPaint(Sender: TObject); | |
| 13 | + | var | |
| 14 | + | image: TBGRABitmap; | |
| 15 | + | c: TBGRAPixel; | |
| 16 | + | begin | |
| 17 | + | image := TBGRABitmap.Create(ClientWidth,ClientHeight, ColorToBGRA(ColorToRGB(clBtnFace)) ); | |
| 18 | + | c := ColorToBGRA(ColorToRGB(clBtnText)); //devuelve el color de texto predeterminado | |
| 19 | + | ||
| 20 | + | image.FontHeight := 30; | |
| 21 | + | image.FontAntialias := true; | |
| 22 | + | image.FontStyle := [fsBold]; | |
| 23 | + | image.TextOut(ClientWidth-5,5,'Hello world',c,); | |
| 24 | + | image.SetPixel(5,5,c); | |
| 25 | + | ||
| 26 | + | image.Draw(Canvas,0,0,True); | |
| 27 | + | image.free; | |
| 28 | + | end; | |
| 29 | + | ``` | |
| 30 | + | ||
| 31 | + | Aquí el tamaño de la fuente está establecido a 30 píxeles, con antiafilado. Usar antiafilado de fuentes es mas lento pero es mas hermoso. | |
| 32 | + | ||
| 33 | + | La esquina superior izquierda del texto está en (5,5). Este origen es mostrado con SetPixel. | |
| 34 | + | ||
| 35 | + | <figure> | |
| 36 | + | <img src="BGRATutorial12a.png" title="BGRATutorial12a.png" /> | |
| 37 | + | <figcaption>BGRATutorial12a.png</figcaption> | |
| 38 | + | </figure> | |
| 39 | + | ||
| 40 | + | #### Usar alineamiento | |
| 41 | + | ||
| 42 | + | Simplemente reemplaza las lineas TextOut y SetPixel con : | |
| 43 | + | ||
| 44 | + | ``` pascal | |
| 45 | + | image.TextOut(ClientWidth-5,5,'Hello world',c,taRightJustify); | |
| 46 | + | image.SetPixel(ClientWidth-5,5,c); | |
| 47 | + | ``` | |
| 48 | + | ||
| 49 | + | Ahora el origen está en el lado derecho de la forma, y el texto está alineado a la derecha. | |
| 50 | + | ||
| 51 | + | <figure> | |
| 52 | + | <img src="BGRATutorial12b.png" title="BGRATutorial12b.png" /> | |
| 53 | + | <figcaption>BGRATutorial12b.png</figcaption> | |
| 54 | + | </figure> | |
| 55 | + | ||
| 56 | + | ### Texto rotado | |
| 57 | + | ||
| 58 | + | Es también simple dibujar texto rotado. Para hacer esto usa TextOutAngle o determina la propiedad FontOrientation : | |
| 59 | + | ||
| 60 | + | ``` pascal | |
| 61 | + | image.TextOutAngle(30,5,-450,'Hello world',c, taLeftJustify); | |
| 62 | + | image.SetPixel(30,5,c); | |
| 63 | + | ``` | |
| 64 | + | ||
| 65 | + | El ángulo se expresa en décimas de grados y el valor positivo significa que va en sentido antihorario. | |
| 66 | + | ||
| 67 | + | <figure> | |
| 68 | + | <img src="BGRATutorial12c.png" title="BGRATutorial12c.png" /> | |
| 69 | + | <figcaption>BGRATutorial12c.png</figcaption> | |
| 70 | + | </figure> | |
| 71 | + | ||
| 72 | + | Fíjate donde está el origen del texto (en el píxel agregado). | |
| 73 | + | ||
| 74 | + | ### Texto ajustado | |
| 75 | + | ||
| 76 | + | Esta es una forma fácil para usar TextRect : | |
| 77 | + | ||
| 78 | + | ``` pascal | |
| 79 | + | image.TextRect(rect(5,5,ClientWidth-5,ClientHeight-5),'This is a text that should be word wrapped',taCenter,tlCenter,c); | |
| 80 | + | image.Rectangle(rect(5,5,ClientWidth-5,ClientHeight-5),c,dmSet); | |
| 81 | + | ``` | |
| 82 | + | ||
| 83 | + | Los parámetros son : | |
| 84 | + | ||
| 85 | + | - el rectángulo delimitador | |
| 86 | + | - el texto | |
| 87 | + | - alineación horizontal | |
| 88 | + | - alineación vertical | |
| 89 | + | - color | |
| 90 | + | ||
| 91 | + | <figure> | |
| 92 | + | <img src="BGRATutorial12d.png" title="BGRATutorial12d.png" /> | |
| 93 | + | <figcaption>BGRATutorial12d.png</figcaption> | |
| 94 | + | </figure> | |
| 95 | + | ||
| 96 | + | ### Texto con sombra | |
| 97 | + | ||
| 98 | + | Puedes hacer un texto sombreado con un efecto de desenfoque : | |
| 99 | + | ||
| 100 | + | ``` pascal | |
| 101 | + | var | |
| 102 | + | image,txt: TBGRABitmap; | |
| 103 | + | grad: TBGRAGradientScanner; | |
| 104 | + | c: TBGRAPixel; | |
| 105 | + | begin | |
| 106 | + | image := TBGRABitmap.Create(ClientWidth,ClientHeight, ColorToBGRA(ColorToRGB(clBtnFace)) ); | |
| 107 | + | c := ColorToBGRA(ColorToRGB(clBtnText)); | |
| 108 | + | ||
| 109 | + | txt := TextShadow(ClientWidth,ClientHeight,'Hello world',30,c,BGRABlack,5,5,5); | |
| 110 | + | image.PutImage(0,0,txt,dmDrawWithTransparency); | |
| 111 | + | txt.Free; | |
| 112 | + | ||
| 113 | + | image.Draw(Canvas,0,0,True); | |
| 114 | + | image.free; | |
| 115 | + | end; | |
| 116 | + | ``` | |
| 117 | + | ||
| 118 | + | El procedimiento TextShadow crea un bitmap que contiene el texto con una sombra. Los parámetros son : | |
| 119 | + | ||
| 120 | + | - El tamaño del bitmap | |
| 121 | + | - El texto | |
| 122 | + | - Alto de la Fuente | |
| 123 | + | - Color de la Fuente | |
| 124 | + | - Color de la sombra | |
| 125 | + | - Desplazamiento de la sombra y tamaño del desenfoque | |
| 126 | + | ||
| 127 | + | No olvides liberar el bitmap luego de utilizarlo. | |
| 128 | + | ||
| 129 | + | <figure> | |
| 130 | + | <img src="BGRATutorial12e.png" title="BGRATutorial12e.png" /> | |
| 131 | + | <figcaption>BGRATutorial12e.png</figcaption> | |
| 132 | + | </figure> | |
| 133 | + | ||
| 134 | + | ### Texto con gradiente | |
| 135 | + | ||
| 136 | + | Como otras funciones de dibujo, puedes proveer de un gradiente o textura para rellenar el texto con el. Aquí hay un ejemplo : | |
| 137 | + | ||
| 138 | + | ``` pascal | |
| 139 | + | uses BGRAGradientScanner; | |
| 140 | + | ||
| 141 | + | var | |
| 142 | + | image: TBGRABitmap; | |
| 143 | + | grad: TBGRAGradientScanner; | |
| 144 | + | begin | |
| 145 | + | image := TBGRABitmap.Create(ClientWidth,ClientHeight, ColorToBGRA(ColorToRGB(clBtnFace)) ); | |
| 146 | + | ||
| 147 | + | grad := TBGRAGradientScanner.Create(BGRA(255,255,0),BGRA(255,0,0),gtLinear,PointF(0,0),PointF(0,35),True,True); | |
| 148 | + | image.FontHeight := 30; | |
| 149 | + | image.FontAntialias := true; | |
| 150 | + | image.FontStyle := [fsBold]; | |
| 151 | + | image.TextOut(6,6,'Hello world',BGRABlack); //dibuja un borde negro | |
| 152 | + | image.TextOut(5,5,'Hello world',grad); //dibuja texto degradado | |
| 153 | + | grad.free; | |
| 154 | + | ||
| 155 | + | image.Draw(Canvas,0,0,True); | |
| 156 | + | image.free; | |
| 157 | + | end; | |
| 158 | + | ``` | |
| 159 | + | ||
| 160 | + | Primero se crea un gradiente horizontal, con color amarillo y rojo. Este se usa como textura. | |
| 161 | + | ||
| 162 | + | <figure> | |
| 163 | + | <img src="BGRATutorial12f.png" title="BGRATutorial12f.png" /> | |
| 164 | + | <figcaption>BGRATutorial12f.png</figcaption> | |
| 165 | + | </figure> | |
| 166 | + | ||
| 167 | + | [[BGRABitmap tutorial 11/es|Tutoría anterior (combinando transformaciones)]] | |
| 168 | + | ||
| 169 | + | --- | |
| 170 | + | *From the Free Pascal wiki, page "BGRABitmap tutorial 12/es", as it stood on 2020-02-09 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).* | |
| 171 | + | Category: Castellano | |
| 172 | + | Category: Español |
