สอนแลป Delphi สดๆ

โดย มิสเตอร์สะตอฯ เมื่อ 25 มกราคม 2009 เวลา 3:00 (เย็น) ในหมวดหมู่ การศึกษา #
อ่าน: 3327

สวัสดีครับทุกท่าน

ทดลองสอนแลปเดลไฟผ่านเว็บลานปัญญานะครับ

สิ่งที่จะเห็นต่อไปนี้เป็นเพียงโคดภาษาเดลไฟนะครับ…..

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 : พืชวัตถุอันตราย…พืชโดนจำคุก…ความผิดของพืชสมุนไพรไทยหรือ? » »


ผู้ใช้ Facebook สามารถให้ความเห็นที่นี่ได้ โดยกด Like เพื่อแสดงตัว

7 ความคิดเห็น

  • #1 น้องจิ ให้ความคิดเห็นเมื่อ 25 มกราคม 2009 เวลา 3:15 (เย็น)

    สอนอย่างนี้ เด็กอักษร งงตึบ 5555++

  • #2 เด็กคอน ให้ความคิดเห็นเมื่อ 25 มกราคม 2009 เวลา 4:52 (เย็น)

    สอนอย่างนี้ก็ดีคะ
    แต่ว่าตอนนี้ตาลายหมดแล้วคะ…..

  • #3 มิสเตอร์สะตอฯ ให้ความคิดเห็นเมื่อ 26 มกราคม 2009 เวลา 9:27 (เช้า)

    สวัสดีครับน้องจิ
    อิๆๆ ตรงตามไวยากรณ์ภาษาคอมพ์ครับ แต่อาจจะไกลจากภาษาคนครับป๋ม

    สวัสดีครับเด็กคอนฯ
    ตาลายเสียแล้วเหรอครับ…ออกลายมาเล้ย ออกลายให้เห็น อิๆๆ  ออตาลายครับ

  • #4 nning ให้ความคิดเห็นเมื่อ 26 มกราคม 2009 เวลา 10:47 (เช้า)

    อย่าว่าแต่เด็กอักษรเลยค่ะ เดิกนิติก็งงด้วย  (อิ อิ …..เด็กด้วยคน)

  • #5 bangsai ให้ความคิดเห็นเมื่อ 26 มกราคม 2009 เวลา 8:02 (เย็น)

    อะจ๊ากกกกก….
    มันเด็งประซา..นะ  แปลว่าไม่รู้เรื่อง

  • #6 สาวตา ให้ความคิดเห็นเมื่อ 26 มกราคม 2009 เวลา 10:59 (เย็น)

    เดาว่าภาษาข้างบน ทำให้เกิดภาพข้างล่างเด้อน้องเด้อ….อ่านไม่รู้เรื่องหรอกจ๊า…เอาวิชาลูกเสือ….หลักอนุมาณมาใช้ค่ะ….ผิดก็ไม่เป็นรายยยยยยยยยยยยยย….แค่ได้ลองไง…..อิอิ

  • #7 kikus ให้ความคิดเห็นเมื่อ 19 มิถุนายน 2010 เวลา 5:01 (เช้า)

    интеретсный блог почему только так мало читателей на нём


แสดงความคิดเห็น

ท่านอยากจะเข้าระบบหรือไม่


*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word


Main: 0.457111120224 sec
Sidebar: 0.25250291824341 sec