我不想别人把我的图片拿去用,想加密,望高手指点,
解决方案 »
- socketconnection连接interbase数据库,如何调用存储过程
- 对dbgrid窗口按标题排序的问题??
- 如何修改 DBGrid 的 列表中的值 ? 例如将数字 0,1,2, 分别修改为字符 开始,结束,等待.
- 如何将毫米(MM)单位转换为像素(Pixel)单位,请大家帮帮忙呀!
- 关于数据库连接问题
- 哪些书合适?
- CSDN的版主進來,請封殺這個搗蛋家伙的ID...
- delphi中有没有类似于VB中的DoEvents的函数?
- 关于函数InTransaction
- 关于COM调试的问题
- 鲨鱼请教:今天面试的问题?
- 哪位给个TdxTreeList控件的源码好吗?ExpressQuantumTreeList 4 FOR D6在我机器上装不了,3Q
如果你要代码,在这里也贴给你:unit ScreenCryptBMP;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, ExtDlgs;type
TFormCrypt = class(TForm)
ButtonLoad: TButton;
ImageOriginal: TImage;
ImageEncrypted: TImage;
ImageDecrypted: TImage;
ButtonEncrypt: TButton;
ButtonDecrypt: TButton;
ButtonSave: TButton;
EditSeedEncrypt: TEdit;
LabelSeedEncrypt: TLabel;
CheckBoxStretch: TCheckBox;
SavePictureDialog: TSavePictureDialog;
OpenPictureDialog: TOpenPictureDialog;
LabelSeedDecrypt: TLabel;
EditSeedDecrypt: TEdit;
procedure FormDestroy(Sender: TObject);
procedure ButtonLoadClick(Sender: TObject);
procedure ButtonEncryptClick(Sender: TObject);
procedure ButtonDecryptClick(Sender: TObject);
procedure CheckBoxStretchClick(Sender: TObject);
procedure EditSeedEncryptChange(Sender: TObject);
procedure EditSeedDecryptChange(Sender: TObject);
procedure EditNumericKeyPress(Sender: TObject; var Key: Char);
procedure ButtonSaveClick(Sender: TObject);
private
BitmapOriginal: TBitmap;
BitmapEncrypted: TBitmap; procedure DecryptImage;
procedure EncryptImage;
public
{ Public declarations }
end;var
FormCrypt: TFormCrypt;implementation
{$R *.DFM}uses
ShellAPI; // ShellExecute
procedure TFormCrypt.EncryptImage;
var
i: INTEGER;
j: INTEGER;
RandomValue: BYTE;
rowIn: pByteArray;
rowOut: pByteArray;
ScanlineByteCount: INTEGER;
begin
if Assigned(BitmapEncrypted)
then BitmapEncrypted.Free; BitmapEncrypted := TBitmap.Create;
BitmapEncrypted.Width := BitmapOriginal.Width;
BitmapEncrypted.Height := BitmapOriginal.Height;
BitmapEncrypted.PixelFormat := BitmapOriginal.PixelFormat; if BitmapOriginal.PixelFormat in [pf1bit, pf4bit, pf8bit]
then BitmapEncrypted.Palette := CopyPalette(BitmapOriginal.Palette); ScanlineByteCount := ABS(Integer(BitmapOriginal.Scanline[1]) -
Integer(BitmapOriginal.Scanline[0])); try
RandSeed := StrToInt(EditSeedEncrypt.Text)
except
RandSeed := 79997 // use this prime number if entry is invalid
end; for j := 0 to BitmapOriginal.Height - 1 do
begin
RowIn := BitmapOriginal.Scanline[j];
RowOut := BitmapEncrypted.Scanline[j]; for i := 0 to ScanlineByteCount - 1 do
begin
RandomValue := Random(256);
RowOut[i] := RowIn[i] xor RandomValue
end
end; ImageEncrypted.Picture.Graphic := BitmapEncrypted; DecryptImage; ButtonDecrypt.Enabled := TRUE;
ButtonSave.Enabled := TRUE
end {EncryptImage};
procedure TFormCrypt.DecryptImage;
var
BitmapDecrypted: TBitmap;
i: INTEGER;
j: INTEGER;
RandomValue: BYTE;
rowIn: pByteArray;
rowOut: pByteArray;
ScanlineByteCount: INTEGER;
begin
BitmapDecrypted := TBitmap.Create;
BitmapDecrypted.Width := BitmapEncrypted.Width;
BitmapDecrypted.Height := BitmapEncrypted.Height;
BitmapDecrypted.PixelFormat := BitmapEncrypted.PixelFormat; // Copy palette if palettized image
if BitmapEncrypted.PixelFormat in [pf1bit, pf4bit, pf8bit]
then BitmapDecrypted.Palette := CopyPalette(BitmapEncrypted.Palette); // This finds the number of bytes per scanline regardless of PixelFormat
ScanlineByteCount := ABS(Integer(BitmapEncrypted.Scanline[1]) -
Integer(BitmapEncrypted.Scanline[0])); try
RandSeed := StrToInt(EditSeedDecrypt.Text)
except
RandSeed := 79997 // use this prime number if entry is invalid
end; for j := 0 to BitmapEncrypted.Height - 1 do
begin
RowIn := BitmapEncrypted.Scanline[j];
RowOut := BitmapDecrypted.Scanline[j]; for i := 0 to ScanlineByteCount - 1 do
begin
RandomValue := Random(256);
RowOut[i] := RowIn[i] xor RandomValue
end
end; ImageDecrypted.Picture.Graphic := BitmapDecrypted;
EditSeedDecrypt.Enabled := TRUE;
end {DecryptImage};
procedure TFormCrypt.FormDestroy(Sender: TObject);
begin
BitmapOriginal.Free;
BitmapEncrypted.Free
end;
procedure TFormCrypt.ButtonLoadClick(Sender: TObject);
begin
if OpenPictureDialog.Execute
then begin
if Assigned(BitmapOriginal)
then BitmapOriginal.Free; BitmapOriginal := TBitmap.Create;
BitmapOriginal.LoadFromFile(OpenPictureDialog.Filename);
ImageOriginal.Picture.Graphic := BitmapOriginal; ButtonEncrypt.Enabled := TRUE;
EditSeedEncrypt.Enabled := TRUE;
end
end;
procedure TFormCrypt.ButtonEncryptClick(Sender: TObject);
begin
EncryptImage
end;
procedure TFormCrypt.ButtonDecryptClick(Sender: TObject);
begin
DecryptImage
end;
procedure TFormCrypt.CheckBoxStretchClick(Sender: TObject);
begin
ImageOriginal.Stretch := CheckBoxStretch.Checked;
ImageEncrypted.Stretch := CheckBoxStretch.Checked;
ImageDecrypted.Stretch := CheckBoxStretch.Checked
end;
procedure TFormCrypt.EditSeedEncryptChange(Sender: TObject);
begin
EncryptImage
end;
procedure TFormCrypt.EditSeedDecryptChange(Sender: TObject);
begin
DecryptImage
end;procedure TFormCrypt.EditNumericKeyPress(Sender: TObject;
var Key: Char);const
Backspace = #$08;
begin
if not (Key in [Backspace, '0'..'9'])
then Key := #$00
end;
procedure TFormCrypt.ButtonSaveClick(Sender: TObject);
begin
if SavePictureDialog.Execute
then BitmapEncrypted.SaveToFile(SavePictureDialog.Filename)
end;end.