Android photo color change

Source: Internet
Author: User

Activity_main.xml:

     
      
       
        
               
  
 
See the MainActivity. java:

package com.example.photocolorchange;import android.os.Bundle;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.ColorFilter;import android.graphics.ColorMatrix;import android.graphics.ColorMatrixColorFilter;import android.graphics.Matrix;import android.graphics.Paint;import android.view.Menu;import android.widget.ImageView;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;public class MainActivity extends Activity {private ImageView iv1;private SeekBar sb1,sb2,sb3,sb4;private Bitmap alertBitmap;private Canvas canvas;private Paint paint;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);iv1 = (ImageView)findViewById(R.id.iv);final Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.shuishou); alertBitmap = Bitmap.createBitmap(bitmap1.getWidth(),bitmap1.getHeight(),bitmap1.getConfig()); paint = new Paint(); canvas = new Canvas(alertBitmap);final Matrix matrix = new Matrix();final ColorMatrix cm = new ColorMatrix();paint.setColorFilter(new ColorMatrixColorFilter(cm));paint.setAntiAlias(true);canvas.drawBitmap(bitmap1, matrix, paint);iv1.setImageBitmap(alertBitmap);sb1 = (SeekBar) findViewById(R.id.sb1);sb2 = (SeekBar) findViewById(R.id.sb2);sb3 = (SeekBar) findViewById(R.id.sb3);sb4 = (SeekBar) findViewById(R.id.sb4);//REDsb1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {int progress = seekBar.getProgress();cm.set(new float[]{progress/128.0f,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(bitmap1, matrix, paint);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub}});//GREENsb2.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {int progress = seekBar.getProgress();cm.set(new float[]{1,0,0,0,0,0,progress/128.0f,0,0,0,0,0,1,0,0,0,0,0,1,0,});paint.setColorFilter(new ColorMatrixColorFilter(cm));canvas.drawBitmap(bitmap1, matrix, paint);iv1.setImageBitmap(alertBitmap);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub}});//BLUEsb3.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {int progress = seekBar.getProgress();cm.set(new float[]{1,0,0,0,0,0,1,0,0,0,0,0,progress/128.0f,0,0,0,0,0,1,0,});paint.setColorFilter(new ColorMatrixColorFilter(cm));canvas.drawBitmap(bitmap1, matrix, paint);iv1.setImageBitmap(alertBitmap);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub}});//sensitometrysb4.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {int progress = seekBar.getProgress();cm.set(new float[]{progress/128.0f,0,0,0,0,0,progress/128.0f,0,0,0,0,0,progress/128.0f,0,0,0,0,0,1,0,});//cm.setSaturation(progress/128.0f);  //saturabilitypaint.setColorFilter(new ColorMatrixColorFilter(cm));canvas.drawBitmap(bitmap1, matrix, paint);iv1.setImageBitmap(alertBitmap);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}

Final result:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.