Develop and Download Open Source Software

Browse Subversion Repository

Contents of /Unit2.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations) (download) (as text)
Mon Jul 20 22:47:05 2015 UTC (8 years, 7 months ago) by yamat0jp
File MIME type: text/x-pascal
File size: 2822 byte(s)
ちょっとだけ工夫しました

リサイズでエディットの値を同期

UIを改良
1 unit Unit2;
2
3 interface
4
5 uses
6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
7 System.Classes, Vcl.Graphics,
8 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ExtDlgs,
9 Vcl.Imaging.pngImage, Vcl.ComCtrls;
10
11 type
12 TForm2 = class(TForm)
13 ScrollBox1: TScrollBox;
14 Image1: TImage;
15 Button1: TButton;
16 Button2: TButton;
17 OpenPictureDialog1: TOpenPictureDialog;
18 SavePictureDialog1: TSavePictureDialog;
19 Edit1: TEdit;
20 Edit2: TEdit;
21 UpDown1: TUpDown;
22 UpDown2: TUpDown;
23 Panel2: TPanel;
24 procedure Button1Click(Sender: TObject);
25 procedure Button2Click(Sender: TObject);
26 procedure Edit1Change(Sender: TObject);
27 private
28 { Private éŒž }
29 public
30 { Public éŒž }
31 end;
32
33 var
34 Form2: TForm2;
35
36 implementation
37
38 {$R *.dfm}
39
40 uses Unit3;
41
42 procedure TForm2.Button1Click(Sender: TObject);
43 var
44 bmp: TBitmap;
45 procedure LoadToBitmap(const FileName: string);
46 var
47 s: TPngImage;
48 t: TPicture;
49 begin
50 if ExtractFileExt(FileName) = '.png' then
51 begin
52 s := TPngImage.Create;
53 try
54 s.LoadFromFile(FileName);
55 bmp.Width:=s.Width;
56 bmp.Height:=s.Height;
57 s.Draw(bmp.Canvas,Rect(0,0,s.Width,s.Height));
58 finally
59 s.Free;
60 end;
61 end
62 else
63 begin
64 t:=TPicture.Create;
65 try
66 t.LoadFromFile(FileName);
67 bmp.Width:=t.Width;
68 bmp.Height:=t.Height;
69 bmp.Assign(t);
70 finally
71 t.Free;
72 end;
73 end;
74 end;
75
76 begin
77 if OpenPictureDialog1.Execute = true then
78 begin
79 bmp:=TBitmap.Create;
80 try
81 LoadToBitmap(OpenPictureDialog1.FileName);
82 Image1.Picture.Bitmap.Assign(bmp);
83 Form3.ClientWidth:=UpDown1.Position;
84 Form3.ClientHeight:=UpDown2.Position;
85 Form3.Show;
86 Form3.Image1.Picture.Bitmap.Assign(bmp);
87 finally
88 bmp.Free;
89 end;
90 end;
91 end;
92
93 procedure TForm2.Button2Click(Sender: TObject);
94 var
95 s: TBitmap;
96 begin
97 if SavePictureDialog1.Execute = true then
98 begin
99 s := TBitmap.Create;
100 try
101 s.Width := Form3.ClientWidth;
102 s.Height := Form3.ClientHeight;
103 SetStretchBltMode(s.Canvas.Handle,HALFTONE);
104 StretchBlt(s.Canvas.Handle,0,0,s.Width,s.Height,Image1.Picture.Bitmap.Canvas.Handle,
105 0,0,Image1.Picture.Bitmap.Width,Image1.Picture.Bitmap.Height,SRCCOPY);
106 s.SaveToFile(SavePictureDialog1.FileName);
107 finally
108 s.Free;
109 end;
110 end;
111 end;
112
113 procedure TForm2.Edit1Change(Sender: TObject);
114 var
115 i: integer;
116 s: TEdit;
117 begin
118 s:=Sender as TEdit;
119 i:=StrToIntDef(s.Text,100);
120 s.Text:=IntToStr(i);
121 if Sender = Edit1 then
122 Form3.ClientWidth:=i
123 else
124 Form3.ClientHeight:=i;
125 end;
126
127 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26