移动搜索栏上的图像显示黑色

时间:2012-09-24 13:14:22

标签: android android-emulator

我在图像视图中显示图像并应用一些彩色滤镜,这是我的代码

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_2);

    SeekBarTxt=(TextView)findViewById(R.id.value_txt);
    iv=(ImageView)findViewById(R.id.img_vw1);

    sb_red = (SeekBar)findViewById(R.id.seek_bar1);
    sb_green = (SeekBar)findViewById(R.id.seek_bar_green);
    sb_blue = (SeekBar)findViewById(R.id.seek_bar_blue);

    sb_red.setOnSeekBarChangeListener(colorBarChangeListener);
    sb_green.setOnSeekBarChangeListener(colorBarChangeListener);
    sb_blue.setOnSeekBarChangeListener(colorBarChangeListener);

    setColorFilter(iv);
}

OnSeekBarChangeListener colorBarChangeListener=new OnSeekBarChangeListener() {

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub
        seekBar.setSecondaryProgress(seekBar.getProgress());
        //SeekBarTxt.setText("ended tracking touch");
    }

    @Override  
    public void onStartTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub
        //SeekBarTxt.setText("starting to track touch");                
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {
        // TODO Auto-generated method stub
        //SeekBarTxt.setText(Integer.toString(progress)+"%");       
        setColorFilter(iv);  
    }
};

private void setColorFilter(ImageView iv)  
{       

    float redValue,greenValue,blueValue;

    if(sb_red.getProgress()!=0 || sb_green.getProgress()!=0 || sb_blue.getProgress()!=0)
    {       
        redValue = ((float)sb_red.getProgress())/255;  
        greenValue = ((float)sb_green.getProgress())/255;   
        blueValue = ((float)sb_blue.getProgress())/255;  
    }
    else
    {
        redValue = 1;  
        greenValue = 1;  
        blueValue = 1;  
    }

     float[] colorMatrix = { 
               redValue, 0, 0, 0, 0,  //red
               0, greenValue, 0, 0, 0, //green
               0, 0, blueValue, 0, 0,  //blue
               0, 0, 0, 1, 0    //alpha    
         }; 

    SeekBarTxt.setText(redValue+"%");
    ColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);

    iv.setColorFilter(colorFilter);
}

现在我的问题是当我滑动搜索栏时,小图像立即变黑,  我想在图像上慢慢地应用色彩效果。我怎么能实现这一点。

请帮忙!

0 个答案:

没有答案