Android 内存位图转换

Android 内存位图转换,android,graphics,bitmap,bit-manipulation,Android,Graphics,Bitmap,Bit Manipulation,我有以下问题。我从一个可以工作的位图转换例程开始 对于任何类型的转变,我都能做到完美无瑕 Bitmap transform(Bitmap src) { // ... any kind of transformation , for example GAMMA double gama = 0.8; int[] tR = new int[256]; int[] gG = new int[256]; int[] tB = new int[256];

我有以下问题。我从一个可以工作的位图转换例程开始 对于任何类型的转变,我都能做到完美无瑕

  Bitmap transform(Bitmap src) {
    // ... any kind of transformation , for example GAMMA
    double gama = 0.8;
    int[] tR = new int[256];
    int[] gG = new int[256];
    int[] tB = new int[256];
    for(int i = 0; i < 256; ++i) {
      tR[i] = (int)Math.min(255, (int)((255.0 * Math.pow(i / 255.0, 1.0 / gama)) + 0.5));
      tG[i] = (int)Math.min(255, (int)((255.0 * Math.pow(i / 255.0, 1.0 / gama)) + 0.5));
      tB[i] = (int)Math.min(255, (int)((255.0 * Math.pow(i / 255.0, 1.0 / gama)) + 0.5));
    }
    // apply transformation to the old bitmap -> bmOut  
    int wid = src.getWidth(), hei = src.getHeight();
    Bitmap bmOut = Bitmap.createBitmap(wid, hei, src.getConfig());
    int A, R, G, B;
    for(int x = 0; x < wid; x++) {
      for(int y = 0; y < hei; y++) {
        int pixel = src.getPixel(x, y);
        A = Color.alpha(pixel);
        R = tR[Color.red(pixel)];
        G = tG[Color.green(pixel)];
        B = tB[Color.blue(pixel)];
        bmOut.setPixel(x, y, Color.argb(A, R, G, B));
      }
    }
    return bmOut;
  }
有人知道我这次做错了什么吗?我不愿意放弃速度 mem阵列解决方案还没有成熟。 谢谢,肖恩,应该是

int off = ( y * wid ) + x;
顺便说一下,我认为这两个循环是不必要的,您可以简单地执行以下操作:

for (int off = pixs.length - 1; off >= 0; off--) 

非常感谢。在20个小时的编码和10杯咖啡让我保持清醒之后,我会变得多么愚蠢,这从未让我感到惊讶。我会毫不犹豫地向全世界展示。总之,将代码简化为一个循环,可以进一步加快速度。它工作得很好。肖恩
int off = ( y * wid ) + x;
for (int off = pixs.length - 1; off >= 0; off--)