1 2 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
   |  
procedure TForm1.Open1Click(Sender: TObject);
var
  PNG : TPNGImage;
  x, y: Integer;
  Pix : pByteArray;
begin
  if OpenPictureDialog1.Execute then // Choix de l'image
  begin
    Caption := OpenPictureDialog1.FileName;
    Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
    if not (Image1.Picture.Graphic is TPNGImage) then // conversion en PNG si nécessaire
    begin
      PNG := TPNGImage.Create;
      try
        PNG.Assign(Image1.Picture.Graphic);
        Image1.Picture.Graphic := PNG;
      finally
        PNG.Free;
      end;
    end;
 
    PNG := Image1.Picture.Graphic as TPNGImage;
    PNG.CreateAlpha; // -> ajoute un canal alpha (si nécessaire)
 
    y := PNG.Height - 1;
    for x := 0 to PNG.Width - 1 do
    begin
      PNG.Pixels[x, 0] := 0; // effacer le pixels en haut et en bas
      PNG.Pixels[x, y] := 0;
    end;
 
    x := PNG.Width - 1;
    for y := 0 to PNG.Height - 1 do
    begin
      PNG.Pixels[0, y] := 0; // effacer les pixels à droite et à gauche
      PNG.Pixels[x, y] := 0;
    end;
 
    Pix := PNG.AlphaScanline[0];
    for x := 0 to PNG.Width - 1 do
    begin
      Pix[x] := 0; // effacer le canal alpha de la première ligne
    end;
    for x := 1 to 5 do
    begin
      Pix[x] := $FF; // définir une zone d'étirement horizontale de 5 pixels à droite et à gauche de l'image
      Pix[PNG.Width - 1 - x] := $FF;
    end;
    for y := 1 to PNG.Height - 2 do
    begin
      Pix := PNG.AlphaScanline[y]; // effacer le canal alpha à droite et à gauche
      Pix[0] := 0;
    end;
    for y := 1 to 5 do
    begin
      Pix := PNG.AlphaScanline[y]; // définir une zone d'étirement verticale de 5 pixels en haut et en bas
      Pix[0] := $FF;
      Pix := PNG.AlphaScanline[PNG.Height - 1 - y];
      Pix[0] := $FF;
    end;
 
    Pix := PNG.AlphaScanLine[PNG.Height - 1];
    Pix[0] := 0;
    for x := 1 to PNG.Width - 2 do
    begin
      Pix[x] := $FF; // définir la zone sensible sur toute la largeur
    end;
    x := PNG.Width - 1;
    Pix[x] := 0;
    for y := 1 to PNG.Height - 2 do
    begin
      Pix := PNG.AlphaScanLine[y]; // définir la zone sensible sur toute la hauteur
      Pix[x] := $FF;
    end;
  end;
 
end; | 
Partager