还是看看我的例子吧,测试通过的哦!
http://expert.csdn.net/Expert/topic/1338/1338296.xml?temp=.6090662

解决方案 »

  1.   

    关于RGBImageFilter类的override,你看看俺的文档吧
    http://www.csdn.net/develop/read_article.asp?id=16488
      

  2.   

    谢谢beyond_xiruo(乱谈情) !
    那我的那个程序哪儿出问题了呢?能帮我看看吗?谢谢啦!
      

  3.   

    其实这不能怪你的程序,你把你使用的图片改用比较小size的,那样装载速度就快了,试试
      

  4.   

    可能不是这个原因吧!因为我换成了一个1.24K的巨小的图片还是一样,一直显示“正在装载图片.....”,呵呵,我的可是P4呀。
    请再帮我看看有其他问题所在吗?
    谢谢beyond_xiruo(乱谈情) 的关注!你给的例子我看了,基本知道思路了,但我的这个为什么不能正常显示,我很迷惑,所以想在你们的帮互下把它搞定!
      

  5.   

    其实很简单的啦,你人工干预一下图片的加载就可以,我改了你的一个方法,如下:
      private void jbInit() throws Exception {
        MediaTracker mt=new MediaTracker(this);
        sourceImage=this.getImage(getCodeBase(),"Jordan.gif");
        mt.addImage(sourceImage,0);
        mt.waitForAll();
        FilterImage=sourceImage;
        mt.addImage(FilterImage,0);
        mt.waitForAll();
        colorFilter=new ColorFilter();
        this.setBackground(Color.white);
      }
      

  6.   

    sorry,简单一些吧
      private void jbInit() throws Exception {
        MediaTracker mt=new MediaTracker(this);
        sourceImage=this.getImage(getCodeBase(),"Jordan.gif");
        FilterImage=sourceImage;
        mt.addImage(sourceImage,0);
        mt.addImage(FilterImage,1);
        mt.waitForAll();
        colorFilter=new ColorFilter();
        this.setBackground(Color.white);
      }
      

  7.   

    我都想哭了!从昨天搞到今天,还是不能出图象呀!
    beyond_xiruo(乱谈情) 我按你的思路把程序改在一个文件中,不用Package了。如下:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.awt.image.*;public class FilterDemo extends Applet implements Runnable{
      private boolean isStandalone = false;  Thread thread=null;
      Graphics g;
      Image sourceImage,FilterImage;
      ColorFilter colorFilter;
      boolean loading=false;
      MediaTracker mt;
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public FilterDemo() {
      }
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception {
        mt=new MediaTracker(this);
        sourceImage=this.getImage(getCodeBase(),"zxz.jpg");
        FilterImage=sourceImage;
        colorFilter=new ColorFilter();
        this.setBackground(Color.white);
      }
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }
      public void run(){
        g=this.getGraphics();
        while(true){
          colorFilter.incrCount();//控制过滤器的设置
          filter();
          g.clipRect(50,50,250,250);//使屏幕的刷新范围为clipRect()指定的范围,该方法用来减
          //轻因为刷新范围大而造成的屏幕的闪烁
          mt.addImage(FilterImage,0);
          try{
            mt.waitForAll();
          }catch(InterruptedException ex){}
          g.drawImage(FilterImage,50,50,250,250,this);
          try{
            Thread.sleep(200);
          }
          catch(InterruptedException e){}
        }
      }
      public void filter(){//生成过滤后的图像
        ImageProducer producer=sourceImage.getSource();
        producer =new FilteredImageSource(producer,colorFilter);
        FilterImage=createImage(producer);
      }
      public void start(){
        if(thread==null){
          thread=new Thread(this);
          thread.start();
        }
      }
      public void stop(){
        if(thread!=null){
          thread.stop();
          thread=null;
        }
      }
    }class ColorFilter extends RGBImageFilter {
      int cr=0xff,cg=0xff,cb=0xff;//记录RGB颜色值
      int count=1;//象素增量
      boolean flag=true;//控制象素增量方向
      public ColorFilter(){}
      public void incrCount(){
        if(count>240) flag=false;
        else if(count<0) flag=true;
        if(flag) count=count+5;
        else count =count-5;
      }
      public int filterRGB(int x, int y, int rgb) {
        //该方法通过count值的变化,完成逐渐减弱或增强图象象素值,使图象更清晰或模糊。
        /**@todo Implement this java.awt.image.RGBImageFilter abstract method*/
        int red=(rgb&0x00ff0000)>>16;
        int green=(rgb&0x0000ff00)>>8;
        int blue=(rgb&0x000000ff);
        if((cr=count)<=red)
          cr=red;
        if((cg=count)<=green)
          cg=green;
        if((cb=count)<=blue)
          cb=blue;
        return 0xff000000|cr<<16|cg<<8|cb;
        //throw new java.lang.UnsupportedOperationException("Method filterRGB() not yet implemented.");
      }
    }
    问题:
        1、我用JCreator编译通过了,但是不能用它运行此Applet,请问Applet在JCreator中运行还需要做哪些配置?
        2、我创建了一个HTML来显示此Applet,但还是不能显示图像,就只有一遍空白。郁闷!!
        3、程序我看了好多遍了,没有问题呀!请热心人在你们的机器上运行一下,看是否是我哪个小地方搞错了。
        4、用了Thread在这里有什么用呀?我没感觉这里需要用Thread呀?
    老天,帮帮忙呀!谢谢!
      

  8.   

    mt.addImage(FilterImage,0);
    mt.waitForAll();
    的位置都没有放对,给你那段代码你乱改个啥,出不来是正常的
    都说了叫你把  private void jbInit() throws Exception这个方法改成我给你那段,你小子乱改
      

  9.   

    请问beyong_xiruo:
    是否应该把一下本分删除呢?public boolean imageUpdate(Image img,int infoflags,int x,int y,int w,int h){
        if(infoflags==ALLBITS){/*经调试我发现程序会进入imageUpdate函数体,但这个判断怎么都不为真,总执行下面的else,也就是说图像装载的过程出问题。请高手帮我看看!*/
          loading=true;
          repaint();
          return false;
        }
        else
          return true;
      }
      public void paint(Graphics g){
        if(!loading)
          this.showStatus("正在装载图片.....");
        else{
          this.showStatus("完成");
          g.drawImage(FilterImage,50,50,250,250,this);
        }
      }
      

  10.   

    ^_^
    问题解决了!太高兴了,其实我最初的那段代码就是正确的,特别感谢beyong_xiruo的帮助,让我受益匪浅!