<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context=".MainActivity" > <ImageView android:id="@+id/imageview" android:layout_width="match_parent" android:layout_height="320dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:text="色 度" android:textSize="18dp" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <SeekBar android:id="@+id/hueBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="5" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:text="饱和度" android:textSize="18dp" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <SeekBar android:id="@+id/saturationBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="5" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:text="亮 度" android:textSize="18dp" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <SeekBar android:id="@+id/lumBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="5" /> </LinearLayout> </LinearLayout>
public static Bitmap handleImageLikePS(Bitmap bp,float hue,float saturation,float lum){
Bitmap bitmap=Bitmap.createBitmap(bp.getWidth(), bp.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(bitmap);
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
ColorMatrix hueMatrix=new ColorMatrix();
hueMatrix.setRotate(0, hue);
hueMatrix.setRotate(1, hue);
hueMatrix.setRotate(2, hue);
ColorMatrix saturationMatrix=new ColorMatrix();
saturationMatrix.setSaturation(saturation);
ColorMatrix lumMatrix=new ColorMatrix();
lumMatrix.setScale(lum,lum,lum,1);
ColorMatrix imageMatrix=new ColorMatrix();
imageMatrix.postConcat(hueMatrix);
imageMatrix.postConcat(saturationMatrix);
imageMatrix.postConcat(lumMatrix);
paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));
canvas.drawBitmap(bp, 0, 0, paint);//此处如果换成bitmap就会仅仅调用一次,图像将不能被编辑
return bitmap;
}
package com.example.colormatrixdemo;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;
public class MainActivity extends Activity implements SeekBar.OnSeekBarChangeListener{
private Bitmap bitmap;
private ImageView imageview;
private SeekBar hueBar,saturationBar,lumBar;
private float mHue,mSaturation ,mLum;
private static int MAXVALUE=255,MIDVALUE=127;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.masuo);
imageview=(ImageView) findViewById(R.id.imageview);
hueBar=(SeekBar) findViewById(R.id.hueBar);
saturationBar=(SeekBar) findViewById(R.id.saturationBar);
lumBar=(SeekBar) findViewById(R.id.lumBar);
hueBar.setOnSeekBarChangeListener(this);
saturationBar.setOnSeekBarChangeListener(this);
lumBar.setOnSeekBarChangeListener(this);
hueBar.setMax(MAXVALUE);
hueBar.setProgress(MIDVALUE);
saturationBar.setMax(MAXVALUE);
saturationBar.setProgress(MIDVALUE);
lumBar.setMax(MAXVALUE);
lumBar.setProgress(MIDVALUE);
imageview.setImageBitmap(bitmap);
}
@Override
public void onProgressChanged(SeekBar seekbar, int progress, boolean arg2) {
switch(seekbar.getId()){
case R.id.hueBar:
mHue=(progress-MIDVALUE)*1.0F/MIDVALUE*180;
break;
case R.id.saturationBar:
mSaturation=progress*1.0F/MIDVALUE;
break;
case R.id.lumBar:
mLum=progress*1.0F/MIDVALUE;
break;
}
imageview.setImageBitmap(ImageTools.handleImageLikePS(bitmap, mHue, mSaturation, mLum));
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有