Ayo Pasang Iklan


Kamis, 07 September 2017

Lazarus : Mengambil Nilai Warna, R,G,B dari Gambar

 Another program iseng,tutor, sekaligus nostalgia plus asah otak kembali yang penulis buat. Nah, pada  program contoh ini mengajarkan bagaimana mengambil nilai pixel dari gambar memakai Lazarus 1.4.4, sedangkan bila hendak memakai Delphi maka hanya di perlukan sedikit perubahan saja.

Gambar form program
Gambar program setelan run ...



unit main;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls, ExtDlgs;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    CEdit: TEdit;
    REdit: TEdit;
    GEdit: TEdit;
    BEdit: TEdit;
    Edit5: TEdit;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    OpenPictureDialog1: TOpenPictureDialog;
    Panel1: TPanel;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
      );
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var pickcolor : TColor;
    RVal,GVal,BVal : Byte;
begin
   If Image1.Picture.Bitmap.Empty <> True Then
   Begin
      pickcolor:= Image1.Picture.Bitmap.Canvas.Pixels[x,y];
      edit5.Text := IntToStr (X) + ',' + IntToStr (Y);
      CEdit.Text := ColorToString(pickcolor);
      RVal:= Red (pickcolor);
      GVal:= Green (pickcolor);
      BVal:= Blue (pickcolor);
      REdit.Text:= IntToStr (RVal)+'($'+ IntToHex (RVal,2)+')';
      GEdit.Text:= IntToStr (GVal)+'($'+ IntToHex (GVal,2)+')';
      BEdit.Text:= IntToStr (BVal)+'($'+ IntToHex (BVal,2)+')';
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   Image1.Picture.Clear;
   If OpenPictureDialog1.Execute Then
   Begin
      Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
   end;
end;

procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
   Image1.Picture.Clear;
end;

end.


***** SEMOGA BERMANFAAT *****

Tidak ada komentar:

Posting Komentar