为背景为透明的图片添加颜色

时间:2016年2月19日13:07:19   
  1. //为图片的透明部分添加背景,颜色为color
  2. public static Bitmap addImageBG(Bitmap bitmap, int color) {
  3. int bitmap_w = bitmap.getWidth();
  4. int bitmap_h = bitmap.getHeight();
  5. int[] arrayColor = new int[bitmap_w * bitmap_h];
  6. int count = 0;
  7. for (int i = 0; i < bitmap_h; i++) {
  8. for (int j = 0; j < bitmap_w; j++) {
  9. int pixelColor = bitmap.getPixel(j, i);
  10. if (pixelColor != 0) {
  11. // TODO: 2/19/2016 如果不是透明想做处理的话在这里进行操作
  12. } else {
  13. pixelColor = color;
  14. }
  15. arrayColor[count] = pixelColor;
  16. count++;
  17. }
  18. }
  19. bitmap = Bitmap.createBitmap(arrayColor, bitmap_w, bitmap_h, Bitmap.Config.ARGB_4444);
  20. return bitmap;
  21. }





posted @ 2016-02-29 18:05  五月的雨  阅读(936)  评论(0编辑  收藏  举报