如何将Bitmap 由不可变变为可变?

我想对现有的一个Bitmap进行操作,比如改变像素!该如何做,期望高人之指点!贴段我需要操作的代码:
  1. public boolean imgdrawimage(Bitmap imgDst,int xDst,int yDst,int widthDst,int heightDst,
  2.                     Bitmap imgsrc,int xSrc,int ySrc,int rop,byte r,byte g,byte b,boolean is){
  3.                
  4.                 if(imgDst==null||imgsrc==null) return false;

  5.                 //rop  RO_OR 0,|或运算,RO_XOR 1, ^异或,RO_COPY 2,RO_NOT 3,
  6.                
  7.                
  8.                 int[] DstPixels =new int[widthDst*heightDst]; //目标位图区域像素数组
  9.                
  10.                 imgDst.getPixels(DstPixels, 0, widthDst, xDst, yDst, widthDst, heightDst);
  11.                
  12.                 Log.v("565", ""+imgDst.getPixel(0, 0));
  13.                
  14.                 int[] SrcPixels = new int[widthDst*heightDst] ; //源位图 区域像素数组
  15.                
  16.                 imgsrc.getPixels(SrcPixels, 0, widthDst, xSrc, ySrc, widthDst, heightDst);
  17.                
  18.                 // 将 源图片按照一定方式 绘制到目标图片上
  19.                 switch(rop){
  20.                     case 0: // |
  21.                            for(int i=0;i<SrcPixels.length;i++){
  22.                                    SrcPixels[i]=SrcPixels[i]|DstPixels[i];
  23.                            }
  24.                        break;
  25.                     case 1: //^
  26.                             for(int i=0;i<SrcPixels.length;i++){
  27.                                     SrcPixels[i]=SrcPixels[i]^DstPixels[i];
  28.                             }
  29.                            break;
  30.                     case 2: // copy
  31.                             for(int i=0;i<SrcPixels.length;i++){
  32.                                     SrcPixels[i]=SrcPixels[i];
  33.                             }
  34.                             break;
  35.                     case 3: // not       
  36.                             for(int i=0;i<SrcPixels.length;i++){
  37.                                     SrcPixels[i]=~SrcPixels[i];
  38.                             }
  39.                             break;
  40.                 }
  41.                 // 将 改变后的像素点 重置到目标图片上
  42.                
  43.                 if(is){ // 如果is 为true ,那么颜色值存在  将源图片数组和此颜色相同的变为完全透明
  44.                        
  45.                         int rgb = getRGB(r,g,b);
  46.                        
  47.                         for(int i=0;i<SrcPixels.length;i++){
  48.                                
  49.                                 if(SrcPixels[i]==rgb){
  50.                                        
  51.                                         SrcPixels[i] =DstPixels[i];
  52.                                        
  53.                                 }
  54.                         }
  55.                 }
  56.                
  57.                
  58. //                bmap = Bitmap.createBitmap(widthDst, heightDst, Config.ARGB_8888);
  59.                
  60.                
  61.                
  62.                 imgDst.setPixels(SrcPixels, 0, widthDst, 0, 0, widthDst, heightDst);
  63.                
  64.                 return true;
  65.         }
  66.    
复制代码

static Bitmap  createBitmap(int[] colors, int width, int height, Bitmap.Config config)
Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.
static Bitmap  createBitmap(int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)
Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.

通过int 数组来构造Bitmap是可行的啊,你的代码不行吗?
少欲、则少烦恼!!!
QQ:1595300672
Blog:http://blog.csdn.net/yxq281426250

TOP

恩,我今天就是这么解决的!可是不知道还有没有高效的算法~!

TOP

强烈推荐 关闭


2010 Google AdSense 合作伙伴日移动专场研讨会大招募!

eoeandroid的创始人之一,eoe公司CTO 姚尚朗(iceskysl)受到 Google 邀请,将在三个城市的《2010 Google AdSense 合作伙伴日移动专场研讨会》上做主题发言, .. ...


查看