/** * ¼òÒ×µ÷É«°å ²½Öè: 1.ʹÓÃSeekBarÀ´¿ØÖÆÑÕÉ«µÄÏÔʾ±ÈÀý * * * @author Áõéª * * 2016-3-3ÏÂÎç10:58:24 */ public class MainActivity extends Activity {
private SeekBar seekbarRed;
private ImageView iv;
private Paint paint;
private Matrix matrix;
private Canvas canvas;
private SeekBar seekbarGreen;
private SeekBar seekbarBlue;
private SeekBar seekbarAlpha;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekbarRed = (SeekBar) findViewById(R.id.seekbar_red);
seekbarGreen = (SeekBar) findViewById(R.id.seekbar_green);
seekbarBlue = (SeekBar) findViewById(R.id.seekbar_blue);
seekbarAlpha = (SeekBar) findViewById(R.id.seekbar_alpha);
iv = (ImageView) findViewById(R.id.iv);
// ͨ¹ýÕâÖÖ·½·¨¶ÁÈ¡µÄbitmapÊÇÖ»¶ÁµÄ£¬²»¿ÉÐÞ¸Ä
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.pre14);
final Bitmap buffImage = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), bitmap.getConfig());
canvas = new Canvas(buffImage);
paint = new Paint();
matrix = new Matrix();
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(buffImage);
seekbarRed.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
int progress = seekBar.getProgress();
float value = progress / 50.0f;
ColorMatrix cm = new ColorMatrix();
/*
*
* ÑÕÉ«¾ØÕó
*/
cm.set(new float[] { 1 * value, 0, 0, 0, 0,//
ºìÉ«
0, 1, 0, 0, 0,// ÂÌÉ«
0, 0, 1, 0, 0,// À¶É«
0, 0, 0, 1, 0,// ͸Ã÷¶È
});
// ¸ø»±ÊÌí¼Ó¹ýÂËÆ÷
// ¸ø»±ÊÌí¼ÓÑÕÉ«¹ýÂËÆ÷
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(buffImage);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
@Override
public void onProgressChanged(SeekBar seekBar,
int progress,
boolean fromUser) {
float value = progress / 50.0f;
ColorMatrix cm = new ColorMatrix();
/*
*
* ÑÕÉ«¾ØÕó
*/
cm.set(new float[] { 1 * value, 0, 0, 0, 0,//
ºìÉ«
0, 1, 0, 0, 0,// ÂÌÉ«
0, 0, 1, 0, 0,// À¶É«
0, 0, 0, 1, 0,// ͸Ã÷¶È
});
// ¸ø»±ÊÌí¼Ó¹ýÂËÆ÷
// ¸ø»±ÊÌí¼ÓÑÕÉ«¹ýÂËÆ÷
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(buffImage);
}
});
seekbarGreen.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
int progress = seekBar.getProgress();
float value = progress / 50.0f;
ColorMatrix cm = new ColorMatrix();
/*
*
* ÑÕÉ«¾ØÕó
*/
cm.set(new float[] { 1, 0, 0, 0, 0,// ºìÉ«
0, 1 * value, 0, 0, 0,// ÂÌÉ«
0, 0, 1, 0, 0,// À¶É«
0, 0, 0, 1, 0,// ͸Ã÷¶È
});
// ¸ø»±ÊÌí¼Ó¹ýÂËÆ÷
// ¸ø»±ÊÌí¼ÓÑÕÉ«¹ýÂËÆ÷
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(buffImage);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
@Override
public void onProgressChanged(SeekBar seekBar,
int progress,
boolean fromUser) {
float value = progress / 50.0f;
ColorMatrix cm = new ColorMatrix();
/*
*
* ÑÕÉ«¾ØÕó
*/
cm.set(new float[] { 1, 0, 0, 0, 0,// ºìÉ«
0, 1 * value, 0, 0, 0,// ÂÌÉ«
0, 0, 1, 0, 0,// À¶É«
0, 0, 0, 1, 0,// ͸Ã÷¶È
});
// ¸ø»±ÊÌí¼Ó¹ýÂËÆ÷
// ¸ø»±ÊÌí¼ÓÑÕÉ«¹ýÂËÆ÷
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(buffImage);
}
});
seekbarBlue.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
int progress = seekBar.getProgress();
float value = progress / 50.0f;
ColorMatrix cm = new ColorMatrix();
/*
*
* ÑÕÉ«¾ØÕó
*/
cm.set(new float[] { 1, 0, 0, 0, 0,// ºìÉ«
0, 1, 0, 0, 0,// ÂÌÉ«
0, 0, 1 * value, 0, 0,// À¶É«
0, 0, 0, 1, 0,// ͸Ã÷¶È
});
// ¸ø»±ÊÌí¼Ó¹ýÂËÆ÷
// ¸ø»±ÊÌí¼ÓÑÕÉ«¹ýÂËÆ÷
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(buffImage);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
@Override
public void onProgressChanged(SeekBar seekBar,
int progress,
boolean fromUser) {
float value = progress / 50.0f;
ColorMatrix cm = new ColorMatrix();
cm.set(new float[] { 1, 0, 0, 0, 0,// ºìÉ«
0, 1, 0, 0, 0,// ÂÌÉ«
0, 0, 1 * value, 0, 0,// À¶É«
0, 0, 0, 1, 0,// ͸Ã÷¶È
});
// ¸ø»±ÊÌí¼Ó¹ýÂËÆ÷
// ¸ø»±ÊÌí¼ÓÑÕÉ«¹ýÂËÆ÷
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(buffImage);
}
});
seekbarAlpha.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
int progress = seekBar.getProgress();
float value = progress / 50.0f;
ColorMatrix cm = new ColorMatrix();
cm.set(new float[] { 1, 0, 0, 0, 0,// ºìÉ«
0, 1, 0, 0, 0,// ÂÌÉ«
0, 0, 1, 0, 0,// À¶É«
0, 0, 0, 1 * value, 0,// ͸Ã÷¶È
});
// ¸ø»±ÊÌí¼Ó¹ýÂËÆ÷
// ¸ø»±ÊÌí¼ÓÑÕÉ«¹ýÂËÆ÷
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(buffImage);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
@Override
public void onProgressChanged(SeekBar seekBar,
int progress,
boolean fromUser) {
float value = progress / 50.0f;
ColorMatrix cm = new ColorMatrix();
cm.set(new float[] { 1, 0, 0, 0, 0,// ºìÉ«
0, 1, 0, 0, 0,// ÂÌÉ«
0, 0, 1, 0, 0,// À¶É«
0, 0, 0, 1 * value, 0,// ͸Ã÷¶È
});
// ¸ø»±ÊÌí¼Ó¹ýÂËÆ÷
// ¸ø»±ÊÌí¼ÓÑÕÉ«¹ýÂËÆ÷
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(buffImage);
}
});
}
} |