簡單的圖片處理器(設定色相,亮度,飽和度)
首先前臺佈局就是選擇的一張圖片,還有三個設定三種顏色引數的seekbar
<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:orientation="vertical" >
<LinearLayout android:layout_height="0dp"
android:layout_width="fill_parent"
android:layout_weight="1">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/touxiang" />
</LinearLayout>
<LinearLayout android:layout_height="50dp"
android:layout_width="fill_parent">
<SeekBar
android:id="@+id/rotateseekBar"
android:layout_width="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<LinearLayout android:layout_height="50dp"
android:layout_width="fill_parent">
<SeekBar
android:id="@+id/saturationseekBar"
android:layout_width="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<LinearLayout android:layout_height="50dp"
android:layout_width="fill_parent">
<SeekBar
android:id="@+id/lumseekBar"
android:layout_width="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
接下來在主佈局的後臺監聽seekbar的changed事件,對圖片進行調整處理
package com.example.imageswitch;
import ImageUtil.BitmapSwitch;
import android.R.integer;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MainActivity extends BitmapSwitch implements OnSeekBarChangeListener {
private ImageView contentImageView;
private SeekBar rotateBar, satutationBar, lumBar;
private static int MAX_VALUE = 255;
private static int MID_VALUE = 127;
//儲存當前seekbar設定的值
private float rvalue,svalue,lvalue;
private Bitmap currentBitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
contentImageView = (ImageView) findViewById(R.id.imageView1);
rotateBar = (SeekBar) findViewById(R.id.rotateseekBar);
satutationBar = (SeekBar) findViewById(R.id.saturationseekBar);
lumBar = (SeekBar) findViewById(R.id.lumseekBar);
currentBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.touxiang);
rotateBar.setOnSeekBarChangeListener(this);
satutationBar.setOnSeekBarChangeListener(this);
lumBar.setOnSeekBarChangeListener(this);
// 設定當前各種屬性的值,和各種屬性最大值
rotateBar.setMax(MAX_VALUE);
rotateBar.setProgress(MID_VALUE);
satutationBar.setMax(MAX_VALUE);
satutationBar.setProgress(MID_VALUE);
lumBar.setMax(MAX_VALUE);
lumBar.setProgress(MID_VALUE);
contentImageView.setImageBitmap(currentBitmap);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
// Bitmap bitmap=
switch (seekBar.getId()) {
case R.id.rotateseekBar:
rvalue=(float) ((progress-MID_VALUE)*1.0F/MID_VALUE*180);//將seekbar獲取的值轉化
break;
case R.id.saturationseekBar:
svalue=(float) ((progress)*1.0F/MID_VALUE);
break;
case R.id.lumseekBar:
lvalue=progress*1.0F/MID_VALUE;
break;
}
//currentBitmap=handBitmap(currentBitmap, rvalue, svalue, lvalue);
contentImageView.setImageBitmap(handBitmap(currentBitmap, rvalue, svalue, lvalue));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
最主要的是實現根據這些引數調整bitmap的工具類
public Bitmap handBitmap(Bitmap bitmap,float rotate,float saturation,float lum){
Bitmap newBitmap=bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas=new Canvas(newBitmap);
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
//0,1,2分別設定R,G,B三種色值
ColorMatrix ratateColorMatrix=new ColorMatrix();
ratateColorMatrix.setRotate(0, rotate);
ratateColorMatrix.setRotate(1, rotate);
ratateColorMatrix.setRotate(2, rotate);
ColorMatrix saturationColorMatrix=new ColorMatrix();
saturationColorMatrix.setSaturation(saturation);
//設定亮度--四個引數是R,G,B,透明度(1表示全透明)
ColorMatrix lumColorMatrix=new ColorMatrix();
lumColorMatrix.setScale(lum, lum, lum, 1);
//將三種效果融合
ColorMatrix allColorMatrix=new ColorMatrix();
allColorMatrix.postConcat(ratateColorMatrix);
allColorMatrix.postConcat(saturationColorMatrix);
allColorMatrix.postConcat(lumColorMatrix);
paint.setColorFilter(new ColorMatrixColorFilter(allColorMatrix));
canvas.drawBitmap(bitmap, 0, 0, paint);
return newBitmap;
}
結果返回一個新的bitmap,再將這個bitmap設定到imageview上,就實現了對圖片的調整。。。
相關文章
- 圖形影像處理之簡單圖片
- 圖片處理擴充套件 Grafika 的簡單使用套件
- 圖片處理擴充套件 Intervention/image 的簡單使用套件
- Python(簡單圖形和檔案處理)程式設計Python程式設計
- android簡單的圖形特效處理Android特效
- 實現一個簡單的基於 WebAssembly 的圖片處理應用Web
- PyTorch - transforms.ColorJitter 改變影像的屬性:亮度(brightness)、對比度(contrast)、飽和度(saturation)和色調(hue)PyTorchORMAST
- 002.00 圖片處理
- Thumbnailator處理圖片AI
- 【YLCircleImageView】圖片處理View
- webpack圖片處理Web
- 圖片上傳及圖片處理
- canvas-修改圖片亮度Canvas
- 002.09 簡單 PNG 圖片編輯器
- 簡單的字串處理字串
- SwiftUI Image 圖片處理SwiftUI
- webpack 圖片處理 loaderWeb
- Python批量處理圖片Python
- 走近webpack(3)–圖片的處理Web
- 攻防世界-簡單的圖片
- 實現簡單的輪播圖(單張圖片、多張圖片)
- SAP UI5 Web Component for React的圖示和圖片處理UIWebReact
- DDGScreenShot —iOS 圖片處理--多圖片拼接 (swift)iOSSwift
- Android中OpenGL濾鏡和RenderScript圖片處理Android
- 圖片編輯工具:FotoJet Photo Editor更好的處理圖片
- 處理圖片流資料
- CGContextRef處理圓形圖片GCContext
- java thumbnailator 做圖片處理JavaAI
- OpenCv--圖片處理操作OpenCV
- java 圖片水印處理類Java
- JavaScript WebGL 圖片透明處理JavaScriptWeb
- webpack(6)webpack處理圖片Web
- Golang 圖片處理 — image 庫Golang
- photoshop常用圖片處理技巧
- android圖片處理,讓圖片變成圓形Android
- SwiftUI圖片處理(縮放、拼圖)SwiftUI
- 影像對比度和亮度
- Flutter-靜態資源和專案圖片的處理Flutter
- Windows設定圖片縮圖Windows