11.5-listing. Slayd-proektor
var
Form1: TForm1;
aSearchRec : TSearchRec;
aPath : String; surat joylashgan katalog
aFile : String; surat fayli
n: integer 0;
iw,ih: integer; Image komponetasining dastlabki o`lchami
implementation
{$R *.DFM}
surat chiqariladigan sohani surat o`lchamiga moslash
Procedure ScaleImage;
var
pw, ph : integer; surat o`lchami
scaleX, scaleY : real; X va Y bo`yicha masshtab
scale : real; masshtab
|
|
11.12-rasm. Picture Editor oynasi
|
11.13-rasm. Slayd-proektor
|
begin
surat yuklandi. Uning o`lchamlari aniqlanmoqda
pw : Form1.Image1.Picture.Width;
ph : Form1.Image1.Picture.Height;
if pw>iw surat eni komponenta enidan katta
then scaleX : iw pw masshtablashtirish lozim
else scaleX : 1;
if ph>ih surat bo`yi komponenta bo`yidan katta
then scaleY : ih ph masshtablashtirish lozim
else scaleY : 1;
eng kichik koeffitsient tanlanmoqda
if scaleX < scaleY
then scale : scaleX
else scale : scaleY;
surat chiqariladigan soha o`lchamini o`zgartirilmoqda
Form1.Image1.Height:
Round(Form1.Image1.Picture.Height*scale);
Form1.Image1.Width:Round(Form1.Image1.Picture.Width*scale);
StrechTrue hamda soha va surat o`lchamlari proportsional
bo`lgani uchun, surat buzilishlarsiz masshtablashtiriladi
end;
birinchi suratni chiqarish
procedure FirstPicture;
var
r : integer; faylni qidirish natijasi
begin
aPath : Form1.Edit1.Text;
r : FindFirst(aPath '*.bmp', faAnyFile, aSearchRec);
if r 0 then
begin
aFile : aPath aSearchRec.Name;
Form1.Image1.Picture.LoadFromFile(aFile); suratni yuklash
ScaleImage;
r : FindNext(aSearchRec); navbatdagi faylni topish
if r 0 then yana suratlar bormi?
Form1.Button1.Enabled : True;
end;
end;
navbatdagi suratni chiqarish
Procedure NextPicture();
var
r : integer;
begin
aFile : aPath aSearchRec.Name;
Form1.Image1.Picture.LoadFromFile(aFile);
ScaleImage;
navbatdagi surat chiqarish uchun tayyorlanmoqda
r : FindNext(aSearchRec); navbatdagi fayl qidirilmoqda
if r <> 0
then boshqa suratlar yo`q
Form1.Button1.Enabled : False;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
Image1.AutoSize : False;
Image1.Stretch : True; masshtablashga ruxsat beramiz
Sohaning dastlabki o`lchamlarini eslab qolindi
iw : Image1.Width;
ih : image1.Height;
Button1.Enabled : False; Navbadagi tugmasiga ruxsat yo`q
FirstPicture; birinchi suratni chiqarilsin
end;
Navbatdagi tugmasi chertilganda
procedure TForm1.Button1Click(Sender: TObject);
begin
NextPicture;
end;
end.
Dastur suratlarni proporsional masshtablashtiradi. Bu masalani to`g’ridan-to`g’ri Strech hususiyatiga True qiymatini berib, hal qilib bo`lmaydi. Birinchi va qolgan suratlarni yuklash hamda chiqarishni mos ravishda FirstPicture va NextPicture protseduralari bajaradi. FirstPicture protsedurasi FindFirst funksiyasidan birinchi uchragan BMP-fayl nomini topadi. FindFirst funksiyasining parametri surat joylashgan papka nomi, asearchRec strukturasi hamda surat fayli niqoblaridan iborat. Agar FindFirst funksiyasi hech bo`lmaganda bitta BMP-fayl mavjud bo`lsa nolga teng bo`ladi. Bunday holda LoadFromFile metodi surat faylini yuklaydi, so`ngra ScaleImage funksiyasi yordamida komponenta o`lchami surat o`lchamiga moslashtiriladi. Yuklangan surat o`lchamlarini Form1.Image1.Picture.Width va Form1.Image1.Picture.Height hususiyat-lariga yordamida aniqlanadi. Ularning qiymatlari Image komponentasi o`lchamlariga bog’liq emas.
Do'stlaringiz bilan baham: |