📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ExtDlgs;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Image1: TImage;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
OpenPictureDialog1: TOpenPictureDialog;
SavePictureDialog1: TSavePictureDialog;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Str : String;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
PByte :PByteArray;
Gray,x,y :Integer;
ImageBmp :TBitmap;
begin
if Str = '' then
showmessage('请选择图片')
else
begin
ImageBmp :=TBitmap.Create;
ImageBmp.Assign(Image1.Picture.Bitmap);
ImageBmp.PixelFormat :=pf24Bit;
for y:=0 to ImageBmp.Height-1 do
begin
PByte := ImageBmp.scanline[y];
for x:=0 to ImageBmp.Width-1 do
begin
Gray:=Round(PByte[x*3+2]*0.3+PByte[x*3+1]*0.59+PByte[x*3]*0.11);
PByte[x*3]:=Gray;
PByte[x*3+1]:=Gray;
PByte[x*3+2]:=Gray;
end;
end;
Image1.Picture.Bitmap.Assign(ImageBmp);
if SavePictureDialog1.Execute then
ImageBmp.SaveToFile(SavePictureDialog1.FileName+'.bmp');
ImageBmp.Free;
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var
Path:string;
begin
path:=ExtractFilePath(application.ExeName)+'Image\';
OpenPictureDialog1.InitialDir := Path;
if OpenPictureDialog1.Execute then
begin
Str := OpenPictureDialog1.FileName;
Image1.Picture.LoadFromFile(Str);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -