码迷,mamicode.com
首页 > 移动开发 > 详细

Android图像处理

时间:2015-04-03 09:20:52      阅读:172      评论:0      收藏:0      [点我收藏+]

标签: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 技术分享 微博

Android图像处理

标签:android   图像处理   色相   饱和度   亮度   

原文地址:http://blog.csdn.net/zhoumushui/article/details/44839929

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!