Android動態修改圖片顏色的實現方式分析


1.修改色相、飽和度、亮度

參看:http://blog.csdn.NET/sjf0115/article/details/7267063 

2.使用透明度通道,獲取圖片輪廓

參看:http://blog.csdn.Net/liu2604592/article/details/7759168

方法:

 

[java]  view plain  copy
  1.  //提取圖像Alpha位圖  
  2.         public static Bitmap getAlphaBitmap(Bitmap mBitmap,int mColor) {  
  3. //          BitmapDrawable mBitmapDrawable = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.enemy_infantry_ninja);  
  4. //          Bitmap mBitmap = mBitmapDrawable.getBitmap();  
  5.               
  6.             //BitmapDrawable的getIntrinsicWidth()方法,Bitmap的getWidth()方法  
  7.             //注意這兩個方法的區別  
  8.             //Bitmap mAlphaBitmap = Bitmap.createBitmap(mBitmapDrawable.getIntrinsicWidth(), mBitmapDrawable.getIntrinsicHeight(), Config.ARGB_8888);  
  9.             Bitmap mAlphaBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Config.ARGB_8888);  
  10.               
  11.             Canvas mCanvas = new Canvas(mAlphaBitmap);  
  12.             Paint mPaint = new Paint();  
  13.               
  14.             mPaint.setColor(mColor);  
  15.             //從原位圖中提取只包含alpha的位圖  
  16.             Bitmap alphaBitmap = mBitmap.extractAlpha();  
  17.             //在畫布上(mAlphaBitmap)繪制alpha位圖  
  18.             mCanvas.drawBitmap(alphaBitmap, 0, 0, mPaint);  
  19.               
  20.             return mAlphaBitmap;  
  21.         }  

 

deviceIV.setDrawingCacheEnabled(true);
        deviceBmp = deviceIV.getDrawingCache();

時常會出現null,原因是超出系統提供最大的DrawingCache值,所以要在此代碼前添加如下代碼:

deviceIV.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        deviceIV.layout(0, 0, deviceIV.getMeasuredWidth(), deviceIV.getMeasuredHeight());

 

 

3.修改圖片像素點的色值,動態修改圖片

參看:http://blog.csdn.net/xys289187120/article/details/6580777


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM