สอนแลป Delphi สดๆ
อ่าน: 4138สวัสดีครับทุกท่าน
ทดลองสอนแลปเดลไฟผ่านเว็บลานปัญญานะครับ
สิ่งที่จะเห็นต่อไปนี้เป็นเพียงโคดภาษาเดลไฟนะครับ…..
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs, Spin;
type
//------ Fast Declaration of Scanline -----//
TRGB32 = packed record
B, G, R, A : Byte;
// R,G,B,Y,A : Byte;
end;
TRGB32Array = packed array[0..MaxInt div SizeOf(TRGB32)-1] of TRGB32;
PRGB32Array = ^TRGB32Array;
//—————————————–//
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Label1: TLabel;
Image2: TImage;
Button2: TButton;
SpinEdit1: TSpinEdit;
Label2: TLabel;
Label3: TLabel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Button2Click(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
If OpenPictureDialog1.Execute Then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
Var
RR, GG, BB, YY : Byte;
begin
RR := GetRValue(Image1.Canvas.Pixels[X,Y]);
GG := GetGValue(Image1.Canvas.Pixels[X,Y]);
BB := GetBValue(Image1.Canvas.Pixels[X,Y]);
YY := Round(0.299*RR + 0.587*GG + 0.114*BB); // Gray-Scale
Label1.Caption := ‘Position(’+IntToStr(X)+’,'+IntToStr(Y)+’) = (’
+ IntToStr(RR) + ‘,’ + InttoStr(GG)+’,'+IntToStr(BB) + ‘,’ +
InttoStr(YY) + ‘)’;
Label1.Refresh;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i,j : integer;
RR, GG, BB, YY, CutValue : Byte;
CountLeafPixel : Integer;
begin
Image2.Width := Image1.Width;
Image2.Height:= Image1.Height;
CountLeafPixel := 0;
CutValue := SpinEdit1.Value;
Image2.Canvas.Brush.Color := clWhite;
Image2.Canvas.Rectangle(0,0,Image2.Width,Image2.Height);
For J:=1 to Image1.Height Do
For I:= 1 to Image1.Width Do
Begin
RR := GetRValue(Image1.Canvas.Pixels[i,j]);
GG := GetGValue(Image1.Canvas.Pixels[i,j]);
BB := GetBValue(Image1.Canvas.Pixels[i,j]);
YY := Round(0.299*RR + 0.587*GG + 0.114*BB); // Gray-Scale
If YY < CutValue then
begin
CountLeafPixel := CountLeafPixel + 1;
Image2.Canvas.Pixels[i,j] := RGB(0,255,0);// RGB(YY,YY,YY);
end;
End;
//ShowMessage(’Amount of Leaf Pixels = ‘ + IntToStr(CountLeafPixel));
Label3.Caption := ‘Amount of Leaf Pixels = ‘ + IntToStr(CountLeafPixel);
Label3.Refresh;
Image2.Refresh;
end;
procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
// Button2Click(Sender);
Button3Click(Sender);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i,j : integer;
RR, GG, BB, YY, CutValue : Byte;
CountLeafPixel : Integer;
Line1, Line2 : PRGB32Array; // For Scanline Uses - Fast Computation;
begin
CountLeafPixel := 0;
CutValue := SpinEdit1.Value;
//—– Scanline Initialization ——-//
with Image1.Picture.Bitmap do
begin
PixelFormat := pf32bit;
Width := Image1.Width;
Height:= Image1.Height;
end;
with Image2.Picture.Bitmap do
begin
PixelFormat := pf32bit;
Width := Image1.Width;
Height:= Image1.Height;
end;
//————————————-//
Image2.Width := Image1.Width;
Image2.Height:= Image1.Height;
Image2.Canvas.Brush.Color := clWhite;
Image2.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
For J:=0 to Image2.Height-1 Do
Begin
Line1 := Image1.Picture.Bitmap.ScanLine[J];
Line2 := Image2.Picture.Bitmap.ScanLine[J];
For I:= 0 to Image2.Width-1 Do
Begin
{
RR := GetRValue(Image1.Canvas.Pixels[i,j]);
GG := GetGValue(Image1.Canvas.Pixels[i,j]);
BB := GetBValue(Image1.Canvas.Pixels[i,j]);
}
RR := Line1[i].B;
GG := Line1[i].G;
BB := Line1[i].R;
YY := Line1[i].A;
// YY := Round(0.299*Line1[i].R + 0.587*Line1[i].G + 0.114*Line1[i].B); // Gray-Scale
YY := Round(0.299*RR + 0.587*GG + 0.114*BB); // Gray-Scale
If YY < CutValue then
begin
CountLeafPixel := CountLeafPixel + 1;
// Image2.Canvas.Pixels[i,j] := RGB(0,255,0);// RGB(YY,YY,YY);
Line2[I].B := 0;
Line2[I].G := 255;
Line2[I].R := 0;
Line2[I].A := 255;
end; // if YY
End; // For I
End; // For J
//ShowMessage(’Amount of Leaf Pixels = ‘ + IntToStr(CountLeafPixel));
Label3.Caption := ‘Amount of Leaf Pixels = ‘ + IntToStr(CountLeafPixel);
Label3.Refresh;
// Image2.Refresh;
Image2.Invalidate;
// Showmessage(’Image1 W = ‘ + inttostr(Image1.Width) +’, H = ‘ + inttostr(Image1.Height)
// +#13#10 +’Image2 W = ‘ + inttostr(Image2.Width) +’, H = ‘ + inttostr(Image2.Height));
end;
End.
« « Prev : เขื่อนแตก น้ำท่วม (Water flooding)
Next : พืชวัตถุอันตราย…พืชโดนจำคุก…ความผิดของพืชสมุนไพรไทยหรือ? » »


9 ความคิดเห็น
สอนอย่างนี้ เด็กอักษร งงตึบ 5555++
สอนอย่างนี้ก็ดีคะ
แต่ว่าตอนนี้ตาลายหมดแล้วคะ…..
สวัสดีครับน้องจิ
อิๆๆ ตรงตามไวยากรณ์ภาษาคอมพ์ครับ แต่อาจจะไกลจากภาษาคนครับป๋ม
สวัสดีครับเด็กคอนฯ
ตาลายเสียแล้วเหรอครับ…ออกลายมาเล้ย ออกลายให้เห็น อิๆๆ ออตาลายครับ
อย่าว่าแต่เด็กอักษรเลยค่ะ เดิกนิติก็งงด้วย (อิ อิ …..เด็กด้วยคน)
อะจ๊ากกกกก….
มันเด็งประซา..นะ แปลว่าไม่รู้เรื่อง
เดาว่าภาษาข้างบน ทำให้เกิดภาพข้างล่างเด้อน้องเด้อ….อ่านไม่รู้เรื่องหรอกจ๊า…เอาวิชาลูกเสือ….หลักอนุมาณมาใช้ค่ะ….ผิดก็ไม่เป็นรายยยยยยยยยยยยยย….แค่ได้ลองไง…..อิอิ
интеретсный блог почему только так мало читателей на нём
batmanapollo.ru
Психолог 2026