import
java.applet.Applet;
import
java.awt.Graphics;
import
java.awt.Color;
import
java.awt.Image;
import
java.awt.image.PixelGrabber;
public class
Aritmetika extends Applet
{
Image img,img2;
int lebar,tinggi;
int lebar2,tinggi2;
int warna, red, green, blue,alpha,
abuabu, tempwarna;
int warna2, red2, green2,
blue2,alpha2, abuabu2, tempwarna2;
String tampil;
String tampil2;
public void init()
{
img=this.getImage(this.getDocumentBase(),
"noblesse.jpg");
lebar
=img.getWidth(this);
img2=this.getImage(this.getDocumentBase(),
"mickey.jpg");
lebar2
=img2.getWidth(this);
}
public void paint(Graphics g)
{
//beri warna pada panel
g.setColor(Color.lightGray);
g.fillRect(0,0,2800,800);
//ambil lebar dan tinggi
citra
lebar =
img.getWidth(this);
tinggi =
img.getHeight(this);
lebar2 =
img.getWidth(this);
tinggi2 =
img.getHeight(this);
//tampilkan informasi
lebar dan tinggi citra
g.setColor(Color.black);
tampil =
String.valueOf(lebar);
g.drawString("lebar:
"+tampil,10,20);
tampil =
String.valueOf(tinggi);
g.drawString("tinggi:
"+tampil,10,40);
g.drawImage(img,10,50,this); //tampilkan citra dengan drawImage
g.drawImage(img2,10,250,this); //tampilkan citra dengan drawImage
int [] pixels = new
int[lebar*tinggi]; //Tentukan panjang
array pixels
int [] pixels2 = new
int[lebar*tinggi]; //Tentukan panjang
array pixels
int [][] bitmapR = new
int[lebar][tinggi]; //Tentukan
panjang array pixels
int [][] bitmapG = new
int[lebar][tinggi]; //Tentukan
panjang array pixels
int [][] bitmapB = new
int[lebar][tinggi]; //Tentukan
panjang array pixels
int [][] bitmapA = new
int[lebar][tinggi]; //Tentukan
panjang array pixels
int [][] bitmapR2 = new
int[lebar][tinggi]; //Tentukan
panjang array pixels
int [][] bitmapG2 = new
int[lebar][tinggi]; //Tentukan panjang
array pixels
int [][] bitmapB2 = new
int[lebar][tinggi]; //Tentukan
panjang array pixels
int [][] bitmapA2 = new
int[lebar][tinggi]; //Tentukan panjang
array pixels
int [][] hasilR = new
int[lebar*2][tinggi*2]; //Tentukan
panjang array pixels
int [][] hasilG = new
int[lebar*2][tinggi*2]; //Tentukan
panjang array pixels
int [][] hasilB = new
int[lebar*2][tinggi*2]; //Tentukan
panjang array pixels
int [][] hasilA = new
int[lebar*2][tinggi*2]; //Tentukan
panjang array pixels
g.drawString("Hasil
Pengolahan",lebar+100,10);
g.drawString("Hasil
Blending RGB",lebar+100,30);
g.drawString("Hasil
Blending Grayscale",lebar+100+lebar+50,30);
g.setColor(Color.black);
PixelGrabber pg = new
PixelGrabber(img,0,0,lebar,tinggi, pixels,0,lebar);
PixelGrabber pg2 = new
PixelGrabber(img2,0,0,lebar2,tinggi2, pixels2,0,lebar2);
try
{
pg.grabPixels(); //grab piksel citra ke object pg.
pg2.grabPixels(); //grab piksel citra ke object pg.
}
catch(InterruptedException
ie)
{
System.out.println("Terjadi
kesalahan saat mengambil data pixels");
ie.printStackTrace();
return;
}
for(int
j=0;j<tinggi;j++)
{
for(int
i=0;i<lebar;i++)
{
warna
= pixels[j*lebar+i];
alpha
= (warna >> 24) & 0xff;
red
= (warna >> 16) & 0xff;
bitmapR[i][j]
= red;
green
= (warna >> 8) & 0xff;
bitmapG[i][j]
= green;
blue
= (warna) & 0xff;
bitmapB[i][j]
= blue;
abuabu
= (red+green+blue)/3;
bitmapA[i][j]=abuabu;
}
}
for(int
j=0;j<tinggi;j++)
{
for(int
i=0;i<lebar;i++)
{
warna2
= pixels2[j*lebar2+i];
alpha2
= (warna2 >> 24) & 0xff;
red2
= (warna2 >> 16) & 0xff;
bitmapR2[i][j]
= red2;
green2
= (warna2 >> 8) & 0xff;
bitmapG2[i][j]
= green2;
blue2
= (warna2) & 0xff;
bitmapB2[i][j]
= blue2;
abuabu2
= (red2+green2+blue2)/3;
bitmapA2[i][j]=abuabu2;
}
}
for(int
j=0;j<tinggi;j++)
{
for(int
i=0;i<lebar;i++)
{
hasilR[i][j]
= (int)(0.6*bitmapR[i][j]+0.4*bitmapR2[i][j]);
hasilG[i][j]
= (int)(0.6*bitmapG[i][j]+0.4*bitmapG2[i][j]);
hasilB[i][j]
= (int)(0.6*bitmapB[i][j]+0.4*bitmapB2[i][j]);
hasilA[i][j]
= (int)(0.6*bitmapA[i][j]+0.4*bitmapA2[i][j]);
}
}
for(int
j=0;j<tinggi;j++)
{
for(int
i=0;i<lebar;i++)
{
//blending
RGB
g.setColor(new
Color(hasilR[i][j],hasilG[i][j],hasilB[i][j]));
g.drawLine(i+lebar+100, j+50, i+lebar+100, j+50);
//blending
abu2
g.setColor(new
Color(hasilA[i][j],hasilA[i][j],hasilA[i][j]));
g.drawLine(i+lebar+100+lebar+50, j+50, i+lebar+100+lebar+50, j+50);
}
}
}
public void repaint(Graphics g)
{
//kosongkan saja
}
}