Android图像处理

在imooc上看了eclipse_xu的课程《Android图像处理》,照葫芦画瓢写了一个Demo:
看一下效果图:
技术分享

核心代码:

package com.zms.imageprocess;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;

/**
 * Created by Administrator on 2015/4/1.
 */
public class PrimaryColorActivity extends Activity {
    private ImageView imageView;
    private SeekBar seekBarHue, seekBarSaturation, seekBarLuminance;
    private float mHue = 0.0f;
    private float mSaturation = 1.0f;
    private float mLuminance = 1.0f;
    private static int MAX_VALUE = 255;
    private static int MID_VALUE = 127;

    private Bitmap bitmap;
    private Button btnReset;
    private int imageFlag = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.primary_color);
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.map);
        imageView = (ImageView) findViewById(R.id.imageView);
        imageView.setImageBitmap(bitmap);
        imageView.setOnClickListener(new MyOnClickListener());

        btnReset = (Button) findViewById(R.id.btnReset);
        btnReset.setOnClickListener(new MyOnClickListener());

        seekBarHue = (SeekBar) findViewById(R.id.seekBarHue);
        seekBarHue.setMax(MAX_VALUE);
        seekBarHue.setProgress(MID_VALUE);
        seekBarHue.setOnSeekBarChangeListener(new MyOnSeekBarChangeListener());

        seekBarSaturation = (SeekBar) findViewById(R.id.seekBarSaturation);
        seekBarSaturation.setMax(MAX_VALUE);
        seekBarSaturation.setProgress(MID_VALUE);
        seekBarSaturation.setOnSeekBarChangeListener(new MyOnSeekBarChangeListener());

        seekBarLuminance = (SeekBar) findViewById(R.id.seekBarLuminance);
        seekBarLuminance.setMax(MAX_VALUE);
        seekBarLuminance.setProgress(MID_VALUE);
        seekBarLuminance.setOnSeekBarChangeListener(new MyOnSeekBarChangeListener());

    }

    class MyOnSeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            switch (seekBar.getId()) {
                case R.id.seekBarHue:
                    mHue = (progress - MID_VALUE) * 1.0F / MID_VALUE * 180;
                    break;
                case R.id.seekBarSaturation:
                    mSaturation = progress * 1.0F / MID_VALUE;
                    break;
                case R.id.seekBarLuminance:
                    mLuminance = progress * 1.0F / MID_VALUE;
                    break;
            }
            imageView.setImageBitmap(ImageHelper.ImageEffect(bitmap, mHue, mSaturation, mLuminance));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    }

    class MyOnClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.imageView:
                    if (imageFlag == 0) {
                        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.aya);
                        imageView.setImageBitmap(bitmap);
                        imageFlag = 1;
                    } else if (imageFlag == 1) {
                        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.map);
                        imageView.setImageBitmap(bitmap);
                        imageFlag = 0;
                    }
                    break;
                case R.id.btnReset:
                    imageView.setImageBitmap(ImageHelper.ImageEffect(bitmap, 0.0f, 1.0f, 1.0f));
                    seekBarHue.setProgress(MID_VALUE);
                    seekBarSaturation.setProgress(MID_VALUE);
                    seekBarLuminance.setProgress(MID_VALUE);
                    break;
            }
        }
    }
}

我在这些地方:技术分享 CSDN 技术分享 GitHub 技术分享 微博

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。