import java.awt.*;
import java.applet.*;
import java.awt.image.*;
public class test2 extends Applet
{
Image pic, bwpic, greypic, redpic, greenpic, bluepic;
public void init()
{
pic = getImage(getDocumentBase(), "bear.gif");
MediaTracker t = new MediaTracker(this);
t.addImage(pic, 0);
try
{
t.waitForAll();
}
catch (Exception e)
{
}
ImageProducer p1 = pic.getSource();
BWFilter BnW = new BWFilter();
bwpic = createImage(new FilteredImageSource(p1, BnW));
ImageProducer p2 = pic.getSource();
GreyFilter grey = new GreyFilter();
greypic = createImage(new FilteredImageSource(p2, grey));
ImageProducer p3 = pic.getSource();
RedFilter red = new RedFilter();
redpic = createImage(new FilteredImageSource(p3, red));
ImageProducer p4 = pic.getSource();
GreenFilter green = new GreenFilter();
greenpic = createImage(new FilteredImageSource(p4, green));
ImageProducer p5 = pic.getSource();
BlueFilter blue = new BlueFilter();
bluepic = createImage(new FilteredImageSource(p5, blue));
}
public void paint(Graphics g)
{
g.drawImage(pic,0, 10, this);
g.drawImage(bwpic, 300, 10, this);
g.drawImage(greypic, 600, 10, this);
g.drawImage(redpic, 0, 400, this);
g.drawImage(greenpic, 300, 400, this);
g.drawImage(bluepic, 600, 400, this);
}
}
class BWFilter extends RGBImageFilter
{
public int filterRGB (int x, int y, int rgb)
{
int alpha = (rgb >> 24) & 0xff;
int red = (int) (((rgb >> 16) & 0xff) * 0.3f);
int green = (int) (((rgb >> 8) & 0xff) * 0.59f);
int blue = (int) (((rgb >> 0) & 0xff) * 0.11f);
int bws = red + green + blue;
if(bws > 127)
{
bws = 255;
}
else
{
bws = 0;
}
return ((alpha & 0xff) << 24) | ((bws & 0xff) << 16) | ((bws & 0xff) << 8) | ((bws & 0xff) << 0);
}
}
class GreyFilter extends RGBImageFilter
{
public int filterRGB (int x, int y, int rgb)
{
int alpha = (rgb >> 24) & 0xff;
int red = (int) (((rgb >> 16) & 0xff) * 0.3f);
int green = (int) (((rgb >> 8) & 0xff) * 0.59f);
int blue = (int) (((rgb >> 0) & 0xff) * 0.11f);
int bws = red + green + blue;
return ((alpha & 0xff) << 24) | ((bws & 0xff) << 16) | ((bws & 0xff) << 8) | ((bws & 0xff) << 0);
}
}
class RedFilter extends RGBImageFilter
{
public int filterRGB(int x, int y, int rgb)
{
return rgb & 0xffff0000;
}
}
class GreenFilter extends RGBImageFilter
{
public int filterRGB(int x, int y, int rgb)
{
return rgb & 0xff00ff00;
}
}
class BlueFilter extends RGBImageFilter
{
public int filterRGB(int x, int y, int rgb)
{
return rgb & 0xff0000ff;
}
}
顺其自然
-
多好的一首 “ 顺其自然 ”
词:姚若龙
作曲:萧煌奇
一份爱会出现裂痕 两个人都要负责任
有些成长来自承认 我终于挣脱怨与恨
年轻总习惯去争论 要别人照我的剧本
满身伤痕才知道悲哀是互不信任
不在乎的眼神内心悄悄破损
在午夜的时分被一个梦给拆穿没忘记那个人
*我试着让生活变得清淡...
13 years ago
1 comments:
One ImageProducer is satisfied to produce those filteredImage.
Credit to Aaron King.
~Jslee
Post a Comment