Mencantumkan kode program di posting Anda, tolong ikuti aturan yang sesuai, baca http://diskusiweb.com/discussion/39204/aturan-cara-menyisipkan-kode-program-di-diskusiweb
Tolong pilih kategori sesuai, jenis posting (pertanyaan atau bukan) dan sertakan tag/topik yang sesuai misal komputer, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus.
need help cara merubah nilai pixel delphi
  • iboy15iboy15
    Posts: 9
    gaaannn tolongin ane dung

    ane di kasi tugas untuk UAS nih

    tugas ny melakukan pencocokan image1 dengan image2 berdasarkan pixel ny
    gan,trus klo pixel ny beda maka ada sebuah button untuk menyamakan
    gambar tersebut dengan menambahkan pixel dari salah satu image tersebut
    agar sama

    untuk pengecekan gambar ny sendiri sudah slesai

    yang jadi maslaah ny button untuk menyamakan gambar ny tersebut (harus melakukan penambahan pixel)

    langsung aja contoh tampilan form ny :
    image

    untuk syntak ny :
    <pre lang="syntak">
    unit Unit6;



    interface



    uses

    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

    Dialogs, ExtCtrls, ExtDlgs, StdCtrls;



    type

    TForm6 = class(TForm)

    Button1: TButton;

    opd: TOpenPictureDialog;

    Button2: TButton;

    Panel1: TPanel;

    Panel2: TPanel;

    Button3: TButton;

    Button4: TButton;

    Image1: TImage;

    Image2: TImage;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure Button4Click(Sender: TObject);

    private

    { Private declarations }

    gambar1,gambar2 : TBitmap;

    public

    { Public declarations }

    end;



    var

    Form6: TForm6;



    implementation



    {$R *.dfm}



    procedure TForm6.Button1Click(Sender: TObject);

    begin

    if not opd.Execute then

    exit

    else

    begin

    gambar1 := Tbitmap.Create;

    gambar1.LoadFromFile(opd.FileName);

    image1.Picture.Bitmap.Assign(gambar1);

    end;

    end;



    procedure TForm6.Button2Click(Sender: TObject);

    begin

    if not opd.Execute then

    exit

    else

    begin

    gambar2 := Tbitmap.Create;

    gambar2.LoadFromFile(opd.FileName);

    image2.Picture.Bitmap.Assign(gambar2);

    end;

    end;



    procedure TForm6.Button3Click(Sender: TObject);

    var pixel1,pixel2 : PByteArray;

    baris,kolom :integer;

    cek : boolean;

    begin

    if ((gambar1.Height=gambar2.Height)and

    (gambar1.Width=gambar2.Width)) then

    begin

    if (gambar1.PixelFormat=gambar2.PixelFormat) then

    begin

    for baris:=0 to gambar1.Height-1 do

    begin

    pixel1:=gambar1.ScanLine[baris];

    pixel2:=gambar2.ScanLine[baris];

    for kolom:=0to gambar1.Width-1do

    begin

    if (gambar1.PixelFormat=pf8bit) then

    begin

    if(pixel1[kolom]=pixel2[kolom]) then

    cek:=true

    else

    begin

    showmessage('Citra Tidak Sama');

    exit;

    end;

    end else

    if (gambar1.PixelFormat=pf24bit) then

    begin

    if ((pixel1[3*kolom]=pixel2[3*kolom]) and

    (pixel1[3*kolom+1]=pixel2[3*kolom+1])and

    (pixel1[3*kolom+2]=pixel2[3*kolom+2]))then

    cek:=true

    else

    begin

    showmessage ('Citra Tidak Sama');

    exit;

    end;

    end;

    end;

    end;

    if cek=true then

    showmessage('citra sama');

    end else

    showmessage('Citra Tidak sama');

    end else

    begin

    showmessage('Citra Tidak sama');

    end;

    end;





    procedure TForm6.Button4Click(Sender: TObject);

    begin

    //ini di isi apa gan ? biar ketika di klik gambar ny bisa sama

    end;



    end.
    </pre>



  • iboy15iboy15
    Posts: 9
    mohon bantuan ny ya suhu delphi
  • promotorpromotor
    Posts: 40
    Sepertinya agan dapet soal jebakan,

    Kalau salah satunya adalah gambar yang jadi patokan BENAR maka ga perlu susah2

    kalo memang tidak sama ya replace aja bitmap nya dengan yang BENAR  dalam hal ini bitmap gambar1

    deklarasikan cek sebagai variabel global.
    Lalu pada Button4Click
    procedure TForm1.Button4Click(Sender: TObject);
    begin
    if(cek)then
    begin
    gambar2.Assign(gambar1);
    image2.Picture.Bitmap.Assign(gambar2);
    end;
    end;
    Jangan lupa Free gambar1 dan gambar2 on form destroy

    tapi klo harus replace per pixel ya coba pake ini pada looping scanline
    IF gambar2.Canvas.Pixels[i,j] <> gambar1.Canvas.Pixels[i,j]
    THEN gambar2.Canvas.Pixels[i,j] := gambar1.Canvas.Pixels[i,j];


  • iboy15iboy15
    Posts: 9
    gk boleh pake assign atau metode yang hanya mengcopy dari salah satu gambar ny mastah
    yup betul mastah gambar 1 jadikan patokaan
    yang di replace itu pixel yang beda aja kan mastah ?
    jadi syntak di atas di masukan ke dalam button 4 kan ?
    cuman itu atau ada penambahan lain ?
    maaf bnyak tanya mastah
    kepepet buat ujian
  • promotorpromotor
    Posts: 40
    di button 4 codenya mencontek punya button 3 trus

    gambar2.Canvas.Pixels[i,j] := gambar1.Canvas.Pixels[i,j]; (sesuaikan koordinat i dan j pixel yang dicek)

    posisinya menggantikan

    showmessage('Citra Tidak Sama');

  • promotorpromotor
    Posts: 40

  • iboy15iboy15
    Posts: 9

  • iboy15iboy15
    Posts: 9
    untuk gambar berformat 8bit gmna gan ?

Selamat datang,

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Tagged

Top Posters