AB

Duas Produces De Imagens

Por Ablank, 04 de fev. de 2008 em Pascal (Delphi)

1
1.3k
AblankA
04 de fevereiro de 2008 às 12:49

Venho aqui hoje mostrar para vocês dois códigos muito interessantes. Como criptografar imagens em Delphi e Transformar ícone em um bitmap :D

 

Vamos ao código:

 

Criptografando uma imagen

 

A Produce:

 

procedure cripto(const BMP: TBitmap; Key: Integer);
var
 BytesPorScan: Integer;
 w, h: integer;
 p: pByteArray;
begin
 try
BytesPorScan := Abs(Integer(BMP.ScanLine[1]) -
Integer(BMP.ScanLine[0]));
 except
raise Exception.Create('Erro !');
 end;
 RandSeed := Key;
 for h := 0 to BMP.Height - 1 do
 begin
P := BMP.ScanLine[h];
for w := 0 to BytesPorScan - 1 do
  P^[w] := P^[w] xor Random(256);
 end;
end;

 

Usando a Produce:

 

No evento onClick de algum botão

 

procedure TForm1.Button1Click(Sender: TObject);
begin
 cripto(Image1.Picture.Bitmap, 1);
 Image1.Refresh;
end;

 

Aqui nos encriptamos uma imagem que estava no form.

 

 

Tranformando Icone em Bitmap

 

 

VAR 
Pic : TPicture;
TI : TIcon;
BEGIN
TI := TIcon.Create;
TI.Handle := ExtractIcon(HInstance, FileNameBuf, 0);
Pic := TPicture.Create;
Pic.Icon := TI;
Image1.Picture := Pic; {TImage}
BitBtn1.Glyph := TBitmap.Create;
WITH BitBtn1.Glyph DO
BEGIN
width := TI.Width;
Height := TI.Height;
Canvas.Draw(0, 0, Pic.Icon);
END;
END;

 

Coloque isso em um botão e crie uma imagebox com a imagem q se quer transformar

 

 

Espero ter ajudado :D