| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 
 |  
procedure TForm1.Button2Click(Sender: TObject);
var
  i, x, y, from_x, from_y : Integer;
  Buffer_Bitmap : TBitmap;
begin
  Randomize;
  // initialise l'image
  Image1.Picture.Bitmap.Width := 200;
  Image1.Picture.Bitmap.Height := 100;
  Image1.Picture.Bitmap.PixelFormat := pf1bit;
  // initialise un buffer
  Buffer_Bitmap := TBitmap.Create;
  Buffer_Bitmap.Width := 200;
  Buffer_Bitmap.Height := 100;
  Buffer_Bitmap.PixelFormat := pf1bit;
  // création de l'image
  with Buffer_Bitmap.Canvas do begin
    // Affiche le code
    Font.Size := 24;
    Font.Style := Font.Style + [fsBold];
    TextOut(10, 30, 'CODE');
    // transformation et affichage de l'image
    // quelques traits
    for i := 0 to 24 do begin
      Buffer_Bitmap.Canvas.MoveTo(Random(Buffer_Bitmap.Width),
                                  Random(Buffer_Bitmap.Height));
      Buffer_Bitmap.Canvas.LineTo(Random(Buffer_Bitmap.Width),
                                  Random(Buffer_Bitmap.Height));
    end;
    // décalage et affichage
    for x := 0 to Buffer_Bitmap.Width - 1 do
      for y := 0 to Buffer_Bitmap.Height - 1 do begin
        from_x := x;
        from_y := y + Round(25 * Cos(x * 0.03));
        // on vérifie de ne pas chercher un pixel en dehors de l'image
        if from_y < 0 then
          from_y := 0;
        if from_y >= Buffer_Bitmap.Height then
          from_y := Buffer_Bitmap.Height;
        Image1.Picture.Bitmap.Canvas.Pixels[x, y] :=
          Buffer_Bitmap.Canvas.Pixels[from_x, from_y];
      end;
  end;
end; | 
Partager