标签:
1 package com.example.day18_03simplemeitu; 2 3 import android.app.Activity; 4 import android.graphics.ColorMatrixColorFilter; 5 import android.os.Bundle; 6 import android.view.Menu; 7 import android.view.MenuItem; 8 import android.widget.ImageView; 9 import android.widget.SeekBar; 10 import android.widget.SeekBar.OnSeekBarChangeListener; 11 12 public class MainActivity extends Activity implements OnSeekBarChangeListener{ 13 14 private ImageView iv_photo; 15 private SeekBar sb_red; 16 private SeekBar sb_green; 17 private SeekBar sb_blue; 18 private SeekBar sb_rgb; 19 private float[] arrays; 20 private ColorMatrixColorFilter cf; 21 22 @Override 23 protected void onCreate(Bundle savedInstanceState) { 24 super.onCreate(savedInstanceState); 25 setContentView(R.layout.activity_main); 26 27 iv_photo = (ImageView) findViewById(R.id.iv_photo); 28 iv_photo.setImageResource(R.drawable.dd); 29 30 31 sb_red = (SeekBar) findViewById(R.id.sb_red); 32 sb_green = (SeekBar) findViewById(R.id.sb_green); 33 sb_blue = (SeekBar) findViewById(R.id.sb_blue); 34 sb_rgb = (SeekBar) findViewById(R.id.sb_rgb); 35 36 37 sb_red.setMax(255); 38 sb_green.setMax(255); 39 sb_blue.setMax(255); 40 sb_rgb.setMax(255); 41 42 43 arrays = new float[] { 1, 0, 0, 0, 0,// red 1*R + 0*G + 0*B + 0*A + 0 44 0, 1, 0, 0, 0,// green 0*R + 1*G + 0*B + 0*A + 0 45 0, 0, 1, 0, 0,// blue 0*R + 0*G + 1*B + 0*A + 0 46 0, 0, 0, 1, 0}; 47 48 cf = new ColorMatrixColorFilter(arrays); 49 50 iv_photo.setColorFilter(cf); 51 52 sb_red.setOnSeekBarChangeListener(this); 53 sb_green.setOnSeekBarChangeListener(this); 54 sb_blue.setOnSeekBarChangeListener(this); 55 sb_rgb.setOnSeekBarChangeListener(this); 56 } 57 58 @Override 59 public void onProgressChanged(SeekBar seekBar, int progress, 60 boolean fromUser) { 61 62 int id =seekBar.getId(); 63 switch (id) { 64 case R.id.sb_red: 65 System.out.println("MainActivity.onProgressChanged() sb_red"+progress); 66 arrays[4] =progress; 67 break; 68 69 case R.id.sb_green: 70 System.out.println("MainActivity.onProgressChanged() sb_green"+progress); 71 arrays[9] =progress; 72 break; 73 case R.id.sb_blue: 74 System.out.println("MainActivity.onProgressChanged() sb_blue"+progress); 75 arrays[14] =progress; 76 break; 77 case R.id.sb_rgb: 78 System.out.println("MainActivity.onProgressChanged() sb_rgb"+progress); 79 arrays[4] =progress; 80 arrays[9] =progress; 81 arrays[14] =progress; 82 83 break; 84 default: 85 break; 86 } 87 88 89 cf = new ColorMatrixColorFilter(arrays); 90 iv_photo.setColorFilter(cf); 91 } 92 93 @Override 94 public void onStartTrackingTouch(SeekBar seekBar) { 95 // TODO Auto-generated method stub 96 } 97 98 @Override 99 public void onStopTrackingTouch(SeekBar seekBar) { 100 // TODO Auto-generated method stub 101 } 102 103 }
标签:
原文地址:http://www.cnblogs.com/woodrow2015/p/4542661.html