我理解的是透明度的改变
你可以这样
取得每个像素的RGB,pic.getRGB(x,y)
new RGB=x001000000+pic.getRGB(x,y)
其中01~ff表示透明度)\0%~100%
oic.setRGB(x,y,newRGB)pic.drawImage(pic,x,y)
你可以这样
取得每个像素的RGB,pic.getRGB(x,y)
new RGB=x001000000+pic.getRGB(x,y)
其中01~ff表示透明度)\0%~100%
oic.setRGB(x,y,newRGB)pic.drawImage(pic,x,y)
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.util.*;public class applet2 extends Applet implements Runnable {
Image img[]=new Image[30];
Image imgx=null;
int imgIndex=0;
int imgAdd=1;
Thread thread=null;
MediaTracker mt;
ImageFilter imgf=null;
FilteredImageSource fis=null;
Image im=null;
Graphics g2=null;
public void init() {
imgx=this.getImage(this.getCodeBase(),"d.jpg");//这里装载图片
mt=new MediaTracker(this);
thread=new Thread(this);
loadImage(mt);
try {
mt.waitForAll();
} catch(Exception ex) {System.err.println(ex.toString());}
im=this.createImage(imgx.getWidth(this),imgx.getHeight(this));
g2=im.getGraphics();
}public void loadImage(MediaTracker mt) {
for(int i=0;i<30;i++) {
imgf=new myImage(imgx.getWidth(this),imgx.getHeight(this),i*8);
fis=new FilteredImageSource(imgx.getSource(),imgf);
img[i]=this.createImage(fis);
mt.addImage(img[i],0);
}
}public void run() {
try {
while(true) {
this.repaint();
Thread.sleep(100);
}
}catch(Exception e) {
System.out.println(e.toString());
}
}public void paint(Graphics g) {
g2.drawImage(img[imgIndex],0,0,this);
g.drawImage(im,0,0,this);
}public void update(Graphics g) {
if(imgIndex>=29)
imgAdd=-1;
if(imgIndex<=0)
imgAdd=1;
imgIndex+=imgAdd;
g2.clearRect(0,0,imgx.getWidth(this),imgx.getHeight(this));
g2.drawImage(img[imgIndex],0,0,this);
g.drawImage(im,0,0,this);
}public void start() {
thread.start();
}public void stop() {
if(thread!=null) {
thread.stop();
thread=null;
}
}
}class myImage extends RGBImageFilter {
int width=0;
int height=0;
int alpha=0;
public myImage(int width,int height,int alpha) {
this.canFilterIndexColorModel=true;
this.width=width;
this.height=height;
this.alpha=alpha;
}public int filterRGB(int x,int y,int rgb) {
DirectColorModel dcm=(DirectColorModel)ColorModel.getRGBdefault();
int red=dcm.getRed(rgb);
int green=dcm.getGreen(rgb);
int blue=dcm.getBlue(rgb);
return alpha<<24|red<<16|green<<8|blue;
}
}