Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   ¿ como Bitmap dibujar lineas onduladas? (https://www.clubdelphi.com/foros/showthread.php?t=72291)

JXJ 09-02-2011 01:03:46

¿ como Bitmap dibujar lineas onduladas?
 
hola
tengo este codigo

Código Delphi [-]
var
  bitmapimagen1: TBitmap;
begin
  bitmapimagen1:=TBitmap.Create;
  bitmapimagen1.Canvas.Brush.Color := clNavy;
  bitmapimagen1.Height:= 200;
  bitmapimagen1.Width:=200;
  bitmapimagen1.PixelFormat := pf24Bit;
end;

¿como puedo dibujar lineas onduladas como difumadas?

como si fueran las que usan los captchas al registrarse
en un sitio web

Ñuño Martínez 09-02-2011 11:10:45

Si vas a manipular bitmaps, los TBitmap no son muy adecuados. Écha un vistazo a la biblioteca Vampyre Imaging Library. En cierto modo son una extensión de TBitmap (de hecho permite intercambiar datos entre ellos), soportan muchos formatos e incluyen ya algunos métodos para aplicar filtros, transformaciones y demás.

Es verdad que para cosas sencillas son un poco "pesadas", pero muy buenas y tal vez te den ideas.

Chris 09-02-2011 18:46:07

O talvez puedas propar la nueva biblioteca DGI+ de Windows. Obtienes resultados asombrosos usada de forma adecuada.

Saludos,
Chris

ecfisa 09-02-2011 23:17:26

Hola JXJ.

Probá si te sirve este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    procedure RotarCaracter(Ch: Char; Angulo,Siguiente: Integer);
    procedure GenerarImagen(NumChar: Byte);
  public
  end;

var
  Form1: TForm1;

implementation {$R *.dfm}

uses DateUtils;

procedure TForm1.RotarCaracter(Ch: Char; Angulo, Siguiente: Integer);
var
  LFont: TLogFont;
  Font: THandle;
begin
  with LFont do
  begin
    lfHeight:= 20;
    lfWidth:=  10;
    lfWeight:= FW_HEAVY;
    lfEscapement:= Angulo;
    lfCharSet:= DEFAULT_CHARSET;
    lfUnderline := Byte(False);
    lfStrikeOut := Byte(True);
  end;
  Font:= CreateFontIndirect(LFont);
  SelectObject(Image1.Canvas.Handle,Font);
  SetTextColor(Image1.canvas.handle,RGB(Random(255)-1,Random(255)-1,Random(255)-1));
  Image1.Canvas.TextOut(Siguiente, 20, Ch);
  DeleteObject(Font);
end;

procedure TForm1.GenerarImagen(NumChar: Byte);
const
  CARACTERES = '01234567890ABCDEFGHIJKLMNPRSTUVWXYZ';
var
  Texto: string;
  i: integer;
begin
  Image1.Picture.LoadFromFile('C:\TEMP\FONDO.BMP'); // rectángulo color claro (mejor blanco)
  RandSeed:= Random(SecondOf(Now));
  Randomize;
  Texto:= '';
  for i:= 1 to NumChar do
     Texto:= Texto + CARACTERES[1 + Random(Length(CARACTERES))];
  if Length(Texto) > NumChar then
     Texto := Copy(Texto, 1, NumChar);
  for i := 1 to Length(Texto) do
     RotarCaracter(Texto[i], Random(900)+1, 20*i-15);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  GenerarImagen(8);
end;

end.

Un saludo.

JXJ 13-02-2011 06:24:44

hola
que raro en dias anteriores no me vbulletin no me dejaba
escribir la respuesta.

bueno .
gracias por su ayuda.

las lineas onduladas las quiero hacer asi.
poniendolas en el fondo de la imagen de forma aleatoria.


ecfisa 13-02-2011 08:32:07

Hola JXJ.

Te había entendido mal, lo que hace el codigo anterior es generar las letras al azar y posicionarlas en ondas como en los captchas.

Para las lineas onduladas se me ocurrió este código pensando en las ondas senoidales:
Código Delphi [-]
...
procedure TForm1.DibujarOnda(PosY,LongitudOnda,Elongacion: Integer; AColor: TColor);
var
  P,C: TCoord;
  i: Integer;
begin
  C.X:= 0;
  C.Y:= 0;
  for i:= 0 to 360 do
  begin
    P.X := Round(i * LongitudOnda);
    P.Y := Round(Sin(i) * Elongacion);
    Image1.Canvas.Pen.Width:= 3;
    Image1.Canvas.Pen.Color:= AColor;
    Image1.Canvas.MoveTo(P.X, PosY+ P.Y);
    Image1.Canvas.LineTo(C.X, PosY+ C.Y);
    C:= P;
  end;
end;

procedure TForm1.DibujarFondo;
const
  Colores: array[1..16] of TColor =(clBlack,clBlue,clGray,clFuchsia,
           clGreen,clLime,clMaroon,clNavy,clOlive,clPurple,clRed,clSilver,
           clYellow,clTeal,clMaroon,clBlue);
var
  i, PosY: Integer;
begin
  Randomize;
  PosY:= 30;
  for i:= 1 to 4 do 
  begin
    DibujarOnda(PosY, Random(50)+20, 20+Random(10), Colores[Random(16)+1]);
    Inc(PosY, Random(20)+50);
  end;
end;
...
Llamada de ejemplo:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
  Image1.Picture.LoadFromFile('C:\TEMP\FONDO.BMP'); //(fondo blanco echo en Paint)
  DibujarFondo;
end;

Muestra:


Espero que te sirva o al menos te aporte alguna idea....;)

Un saludo.

JXJ 14-02-2011 20:14:27

excelente

Gracias eficsa eso es .


La franja horaria es GMT +2. Ahora son las 23:36:14.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi