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 sb_red = (SeekBar) findViewById(R.id.sb_red); 31 sb_green = (SeekBar) findViewById(R.id.sb_green); 32 sb_blue = (SeekBar) findViewById(R.id.sb_blue); 33 sb_rgb = (SeekBar) findViewById(R.id.sb_rgb); 34 35 sb_red.setMax(255); 36 sb_green.setMax(255); 37 sb_blue.setMax(255); 38 sb_rgb.setMax(255); 39 40 arrays = new float[] { 1, 0, 0, 0, 0,// red 1*R + 0*G + 0*B + 0*A + 0 41 0, 1, 0, 0, 0,// green 0*R + 1*G + 0*B + 0*A + 0 42 0, 0, 1, 0, 0,// blue 0*R + 0*G + 1*B + 0*A + 0 43 0, 0, 0, 1, 0}; 44 45 cf = new ColorMatrixColorFilter(arrays); 46 47 iv_photo.setColorFilter(cf); 48 49 sb_red.setOnSeekBarChangeListener(this); 50 sb_green.setOnSeekBarChangeListener(this); 51 sb_blue.setOnSeekBarChangeListener(this); 52 sb_rgb.setOnSeekBarChangeListener(this); 53 } 54 55 @Override 56 public void onProgressChanged(SeekBar seekBar, int progress, 57 boolean fromUser) { 58 59 int id =seekBar.getId(); 60 switch (id) { 61 case R.id.sb_red: 62 System.out.println("MainActivity.onProgressChanged() sb_red"+progress); 63 arrays[4] =progress; 64 break; 65 66 case R.id.sb_green: 67 System.out.println("MainActivity.onProgressChanged() sb_green"+progress); 68 arrays[9] =progress; 69 break; 70 case R.id.sb_blue: 71 System.out.println("MainActivity.onProgressChanged() sb_blue"+progress); 72 arrays[14] =progress; 73 break; 74 case R.id.sb_rgb: 75 System.out.println("MainActivity.onProgressChanged() sb_rgb"+progress); 76 arrays[4] =progress; 77 arrays[9] =progress; 78 arrays[14] =progress; 79 80 break; 81 default: 82 break; 83 } 84 cf = new ColorMatrixColorFilter(arrays); 85 iv_photo.setColorFilter(cf); 86 } 87 88 @Override 89 public void onStartTrackingTouch(SeekBar seekBar) { 90 // TODO Auto-generated method stub 91 } 92 93 @Override 94 public void onStopTrackingTouch(SeekBar seekBar) { 95 // TODO Auto-generated method stub 96 } 97 }
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:paddingBottom="@dimen/activity_vertical_margin" 6 android:paddingLeft="@dimen/activity_horizontal_margin" 7 android:paddingRight="@dimen/activity_horizontal_margin" 8 android:paddingTop="@dimen/activity_vertical_margin" 9 tools:context="com.example.day18_03simplemeitu.MainActivity" 10 android:orientation="vertical" > 11 12 <SeekBar 13 android:id="@+id/sb_red" 14 android:layout_width="match_parent" 15 android:layout_height="wrap_content" 16 /> 17 <SeekBar 18 android:id="@+id/sb_green" 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 /> 22 <SeekBar 23 android:id="@+id/sb_blue" 24 android:layout_width="match_parent" 25 android:layout_height="wrap_content" 26 /> 27 <SeekBar 28 android:id="@+id/sb_rgb" 29 android:layout_width="match_parent" 30 android:layout_height="wrap_content" 31 /> 32 <ImageView 33 android:id="@+id/iv_photo" 34 android:layout_width="wrap_content" 35 android:layout_height="wrap_content" 36 /> 37 </LinearLayout>