Android編程實(shí)現(xiàn)圖片的顏色處理功能示例
本文實(shí)例講述了Android編程實(shí)現(xiàn)圖片的顏色處理功能。分享給大家供大家參考,具體如下:
先看效果圖:

圖片的顏色處理的基本步驟:
1.先拿到一張?jiān)瓐D
2.拿到一張和原圖一樣的紙
3.把紙固定在畫板上
4.顏色的取值
5.進(jìn)度條的拖動(dòng)與監(jiān)聽
代碼編寫:
布局:
<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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="青--紅" />
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/red_seekbar"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="青--綠" />
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/green_seekbar"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="青--藍(lán)" />
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/blue_seekbar"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/im"
android:src="@drawable/img_small_1"/>
</LinearLayout>
activity:
public class MainActivity extends Activity implements OnSeekBarChangeListener{
private SeekBar red_sb,green_sb,blue_sb;
private ImageView imageView;
private Canvas canvas;
private Paint paint;
private Bitmap baseBitmap,copyBitmap;
private float red_vector,green_vector,blue_vector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
red_sb=(SeekBar) findViewById(R.id.red_seekbar);
green_sb=(SeekBar) findViewById(R.id.green_seekbar);
blue_sb=(SeekBar) findViewById(R.id.blue_seekbar);
imageView=(ImageView) findViewById(R.id.im);
red_sb.setOnSeekBarChangeListener(this);
green_sb.setOnSeekBarChangeListener(this);
blue_sb.setOnSeekBarChangeListener(this);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
int progress=seekBar.getProgress();
float count=progress/50f;//使拖動(dòng)條的取值為0f-2f,滿足我們的取值要求
switch (seekBar.getId()) {
case R.id.red_seekbar:
this.red_vector=count;
break;
case R.id.green_seekbar:
this.green_vector=count;
break;
case R.id.blue_seekbar:
this.blue_vector=count;
break;
default:
break;
}
//主題代碼
baseBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.img_small_1);
copyBitmap=Bitmap.createBitmap(baseBitmap.getWidth(), baseBitmap.getHeight(), baseBitmap.getConfig());
canvas=new Canvas(copyBitmap);
Matrix matrix=new Matrix();
paint=new Paint();
//vector:取值范圍(0-2)
float[] colors=new float[]{
red_vector,0,0,0,0,
0,green_vector,0,0,0,
0,0,blue_vector,0,0,
0,0,0,1,0};
paint.setColorFilter(new ColorMatrixColorFilter(colors));
canvas.drawBitmap(baseBitmap, matrix, paint);
imageView.setImageBitmap(copyBitmap);
}
}
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android實(shí)現(xiàn)可滑動(dòng)的自定義日歷控件
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)可滑動(dòng)的自定義日歷控件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07
淺析Android中g(shù)etWidth()和getMeasuredWidth()的區(qū)別
這篇文章主要介紹了淺析Android中g(shù)etWidth()和getMeasuredWidth()的區(qū)別 ,getMeasuredWidth()獲取的是view原始的大小,getWidth()獲取的是這個(gè)view最終顯示的大小,具體區(qū)別介紹大家參考下本文2018-04-04
android自定義滾動(dòng)上下回彈scollView
這篇文章主要為大家詳細(xì)介紹了android自定義滾動(dòng)上下回彈scollView,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
Android應(yīng)用中設(shè)置alpha值來制作透明與漸變效果的實(shí)例
這篇文章主要介紹了Android應(yīng)用中設(shè)置alpha值來制作透明與漸變效果的實(shí)例,展示了基礎(chǔ)的透明漸變動(dòng)畫的編寫方法,需要的朋友可以參考下2016-04-04
Android實(shí)現(xiàn)自定義圓角對話框Dialog的示例代碼
項(xiàng)目中多處用到對話框,本篇文章主要介紹了Android實(shí)現(xiàn)圓角對話框Dialog的示例代碼,有興趣的可以了解一下。2017-03-03
Android使用Service實(shí)現(xiàn)IPC通信的2種方式
這篇文章主要介紹了Android使用Service實(shí)現(xiàn)IPC通信的2種方式,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
Android WebView通過動(dòng)態(tài)的修改js去攔截post請求參數(shù)實(shí)例
這篇文章主要介紹了Android WebView通過動(dòng)態(tài)的修改js去攔截post請求參數(shù)實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03

