import
java.applet.Applet;
import
java.awt.Graphics;
import
java.awt.Color;
import
java.awt.Image;
import java.awt.image.PixelGrabber;
import
java.lang.*;
public
class transit extends Applet{
Image img;
int lebar, tinggi;
int warna, red, green, blue, alpha,
abuabu, tempwarna, aa, bb;
String tampil;
public void init()
{
img=this.getImage(this.getDocumentBase(),
"wtp.jpg");
lebar=img.getWidth(this);
tinggi=img.getHeight(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);
//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);
//tampilkan citra dengan
drawImage
g.drawImage(img,10,50,this);
int[] pixels=new
int[lebar*tinggi]; //Tentukan panjang array pixels
PixelGrabber pg=new
PixelGrabber(img, 0, 0, lebar, tinggi, pixels, 0, lebar);
try
{
pg.grabPixels();
//grab piksel citra ke object pg.
}
catch
(InterruptedException ie)
{
System.out.println("Terjadi
kesalahan saat mengambil data pixels");
ie.printStackTrace();
return;
}
g.drawString("Hasil
Pengolahan", lebar+100, 20);
g.drawString("Normal",
lebar+100, 40);
g.drawString("Translasi",
lebar+100+lebar+50, 40);
g.drawString("Scaling
Perkecil", lebar+100, 40+tinggi+30);
g.drawString("Scaling
Perbesar", lebar+100+lebar+50, 40+tinggi+30);
g.drawString("Rotasi",
lebar+100+lebar+50+lebar+50, 40);
g.drawString("Replikasi",
lebar+100, 40+tinggi+30+tinggi+tinggi+30);
g.drawString("Interpolasi",
lebar+100+lebar+lebar+50, 40+tinggi+30+tinggi+tinggi+30);
g.setColor(Color.black);
//pembentukan bitmap
int[][] bitmapR = new
int[lebar+1][tinggi+1];
int[][] bitmapG = new
int[lebar+1][tinggi+1];
int[][] bitmapB = new
int[lebar+1][tinggi+1];
int[][] hasilbitmapR =
new int[lebar*2][tinggi*2];
int[][] hasilbitmapG =
new int[lebar*2][tinggi*2];
int[][] hasilbitmapB =
new int[lebar*2][tinggi*2];
int[][] scbitmapR = new
int[lebar*2][tinggi*2];
int[][] scbitmapG = new
int[lebar*2][tinggi*2];
int[][] scbitmapB = new
int[lebar*2][tinggi*2];
int[][] scbitmapR1 = new
int[lebar*2][tinggi*2];
int[][] scbitmapG1 = new
int[lebar*2][tinggi*2];
int[][] scbitmapB1 = new
int[lebar*2][tinggi*2];
int[][] repbitmapR = new
int[lebar*2][tinggi*2];
int[][] repbitmapG = new
int[lebar*2][tinggi*2];
int[][] repbitmapB = new
int[lebar*2][tinggi*2];
int[][] inbitmapR = new
int[lebar*2][tinggi*2];
int[][] inbitmapG = new
int[lebar*2][tinggi*2];
int[][] inbitmapB = new
int[lebar*2][tinggi*2];
int[][] rotbitmapR = new
int[lebar*2][tinggi*2];
int[][] rotbitmapG = new
int[lebar*2][tinggi*2];
int[][] rotbitmapB = new
int[lebar*2][tinggi*2];
//penggeseran dan
pengisian warna
for(int j=0;
j<tinggi; j++)
{
for(int i=0;
i<lebar; i++)
{
warna=pixels[j*lebar+i];
red=(warna
>> 16) & 0xff;
bitmapR[i][j]=red;
green=(warna
>> 8) & 0xff;
bitmapG[i][j]=green;
blue=(warna)
& 0xff;
bitmapB[i][j]=blue;
}
}
int i, j;
int x=0;
int y=0;
double
sudut=Math.toRadians(15);
for(j=0; j<tinggi; j++)
{
for(i=0;
i<lebar; i++)
{
//translasi
hasilbitmapR[i+10][j+10]
= bitmapR[i][j];
hasilbitmapG[i+10][j+10] = bitmapG[i][j];
hasilbitmapB[i+10][j+10] = bitmapB[i][j];
//scaling
0.5
scbitmapR[i/2][j/2]
= bitmapR[i][j];
scbitmapG[i/2][j/2] = bitmapG[i][j];
scbitmapB[i/2][j/2] = bitmapB[i][j];
//scaling
2x
scbitmapR1[i*2][j*2]
= bitmapR[i][j];
scbitmapG1[i*2][j*2] = bitmapG[i][j];
scbitmapB1[i*2][j*2] = bitmapB[i][j];
//replikasi
int
tempsx= i*2;
int
tempsy;
repbitmapR[(int)(Math.floor(i*2))][(int)(Math.floor(j*2))]
= bitmapR[i][j];
repbitmapG[(int)(Math.floor(i*2))][(int)(Math.floor(j*2))] = bitmapG[i][j];
repbitmapB[(int)(Math.floor(i*2))][(int)(Math.floor(j*2))] = bitmapB[i][j];
tempsx=(int)(Math.floor(i*2));
while(tempsx<(i+1)*2){
tempsy=(int)(Math.floor(j*2));
while(tempsy<(j+1)*2){
repbitmapR[tempsx][tempsy]
= bitmapR[i][j];
repbitmapG[tempsx][tempsy]
= bitmapG[i][j];
repbitmapB[tempsx][tempsy]
= bitmapB[i][j];
tempsy++;
}
tempsx++;
}
//interpolasi
inbitmapR[i*2][j*2]
= bitmapR[i][j];
inbitmapG[i*2][j*2]
= bitmapG[i][j];
inbitmapB[i*2][j*2]
= bitmapB[i][j];
inbitmapR[i*2+1][j*2+1]
= (bitmapR[i][j]+bitmapR[i+1][j+1])/2;
inbitmapG[i*2+1][j*2+1]
= (bitmapG[i][j]+bitmapG[i+1][j+1])/2;
inbitmapB[i*2+1][j*2+1]
= (bitmapB[i][j]+bitmapB[i+1][j+1])/2;
inbitmapR[i*2+1][j*2]
= (bitmapR[i][j]+bitmapR[i+1][j])/2;
inbitmapG[i*2+1][j*2]
= (bitmapG[i][j]+bitmapG[i+1][j])/2;
inbitmapB[i*2+1][j*2]
= (bitmapB[i][j]+bitmapB[i+1][j])/2;
inbitmapR[i*2][j*2+1]
= (bitmapR[i][j]+bitmapR[i][j+1])/2;
inbitmapG[i*2][j*2+1]
= (bitmapG[i][j]+bitmapG[i][j+1])/2;
inbitmapB[i*2][j*2+1]
= (bitmapB[i][j]+bitmapB[i][j+1])/2;
//rotasi
aa=(int)(Math.cos(sudut)*i-Math.sin(sudut)*j);
bb=(int)(Math.sin(sudut)*i+Math.cos(sudut)*j);
if(aa>=0
&& bb>=0){
rotbitmapR[aa][bb] = bitmapR[i][j];
rotbitmapG[aa][bb]
= bitmapG[i][j];
rotbitmapB[aa][bb]
= bitmapB[i][j];
}
}
}
for(j=0; j<tinggi;
j++)
{
for(i=0;
i<lebar; i++)
{
//normal
g.setColor(new
Color(bitmapR[i][j], bitmapG[i][j], bitmapB[i][j]));
g.drawLine(i+lebar+100,
j+50, i+lebar+100, j+50);
//translasi
g.setColor(new
Color(hasilbitmapR[i][j], hasilbitmapG[i][j], hasilbitmapB[i][j]));
g.drawLine(i+lebar+100+lebar+50,
j+50, i+lebar+100+lebar+50, j+50);
//rotasi
g.setColor(new
Color(rotbitmapR[i][j], rotbitmapG[i][j], rotbitmapB[i][j]));
g.drawLine(i+lebar+100+lebar+50+lebar+50,
j+50, i+lebar+100+lebar+50+lebar+50, j+50);
}
}
for(j=0; j<tinggi/2;
j++)
{
for(i=0; i<lebar/2;
i++)
{
//scaling
0.5
g.setColor(new
Color(scbitmapR[i][j], scbitmapG[i][j], scbitmapB[i][j]));
g.drawLine(i+lebar+100,
j+40+tinggi+40, i+lebar+100, j+40+tinggi+40);
}
}
for(j=0; j<tinggi*2;
j++)
{
for(i=0;
i<lebar*2; i++)
{
//scaling
2x
g.setColor(new
Color(scbitmapR1[i][j], scbitmapG1[i][j], scbitmapB1[i][j]));
g.drawLine(i+lebar+100+lebar+50,
j+40+tinggi+40, i+lebar+100+lebar+50, j+40+tinggi+40);
}
}
for(j=0;
j<(tinggi*2); j++)
{
for(i=0;
i<(lebar*2); i++)
{
//replikasi
g.setColor(new
Color(repbitmapR[i][j], repbitmapG[i][j], repbitmapB[i][j]));
g.drawLine(i+lebar+100,
j+40+tinggi+40+tinggi+tinggi+30, i+lebar+100, j+40+tinggi+40+tinggi+tinggi+30);
}
}
for(j=0; j<tinggi*2;
j++)
{
for(i=0;
i<lebar*2; i++)
{
//interpolasi
g.setColor(new
Color(inbitmapR[i][j], inbitmapG[i][j], inbitmapB[i][j]));
g.drawLine(i+lebar+100+lebar+lebar+50,
j+40+tinggi+40+tinggi+tinggi+30, i+lebar+100+lebar+lebar+50, j+40+tinggi+40+tinggi+tinggi+30);
}
}
}
public void repaint(Graphics g)
{
//kosongkan saja
}
}
0 komentar:
Posting Komentar