這篇文章將為大家詳細(xì)講解有關(guān)Android中怎么對圖片的顏色進(jìn)行處理,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
成都創(chuàng)新互聯(lián)一直秉承“誠信做人,踏實(shí)做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個(gè)客戶多一個(gè)朋友!為您提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、成都網(wǎng)頁設(shè)計(jì)、小程序設(shè)計(jì)、成都網(wǎng)站開發(fā)、成都網(wǎng)站制作、成都軟件開發(fā)、成都app軟件開發(fā)公司是成都本地專業(yè)的網(wǎng)站建設(shè)和網(wǎng)站設(shè)計(jì)公司,等你一起來見證!
布局:
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;//使拖動條的取值為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中怎么對圖片的顏色進(jìn)行處理就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。