这篇文章将为大家详细讲解有关Android中怎么对图片的颜色进行处理,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
成都创新互联公司是一家专业提供寻乌企业网站建设,专注与成都网站建设、网站设计、H5页面制作、小程序制作等业务。10年已为寻乌众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。布局:
activity:
public class MainActivity extends Activity implements OnSeekBarChangeListener{ private SeekBar red_sb,green_sb,blue_sb; private ImageView imageView; private Canvas canvas; private Paint paint; private Bitmap baseBitmap,copyBitmap; private float red_vector,green_vector,blue_vector; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); red_sb=(SeekBar) findViewById(R.id.red_seekbar); green_sb=(SeekBar) findViewById(R.id.green_seekbar); blue_sb=(SeekBar) findViewById(R.id.blue_seekbar); imageView=(ImageView) findViewById(R.id.im); red_sb.setOnSeekBarChangeListener(this); green_sb.setOnSeekBarChangeListener(this); blue_sb.setOnSeekBarChangeListener(this); } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub int progress=seekBar.getProgress(); float count=progress/50f;//使拖动条的取值为0f-2f,满足我们的取值要求 switch (seekBar.getId()) { case R.id.red_seekbar: this.red_vector=count; break; case R.id.green_seekbar: this.green_vector=count; break; case R.id.blue_seekbar: this.blue_vector=count; break; default: break; } //主题代码 baseBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.img_small_1); copyBitmap=Bitmap.createBitmap(baseBitmap.getWidth(), baseBitmap.getHeight(), baseBitmap.getConfig()); canvas=new Canvas(copyBitmap); Matrix matrix=new Matrix(); paint=new Paint(); //vector:取值范围(0-2) float[] colors=new float[]{ red_vector,0,0,0,0, 0,green_vector,0,0,0, 0,0,blue_vector,0,0, 0,0,0,1,0}; paint.setColorFilter(new ColorMatrixColorFilter(colors)); canvas.drawBitmap(baseBitmap, matrix, paint); imageView.setImageBitmap(copyBitmap); } }
关于Android中怎么对图片的颜色进行处理就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。