Пример #1
0
 private static int blendColors(int color1, int color2, float factor) {
   final float inverseFactor = 1f - factor;
   float a = (Color.alpha(color1) * factor) + (Color.alpha(color2) * inverseFactor);
   float r = (Color.red(color1) * factor) + (Color.red(color2) * inverseFactor);
   float g = (Color.green(color1) * factor) + (Color.green(color2) * inverseFactor);
   float b = (Color.blue(color1) * factor) + (Color.blue(color2) * inverseFactor);
   return Color.argb((int) a, (int) r, (int) g, (int) b);
 }
Пример #2
0
    private int rotateColor(int color, float rad) {
      float deg = rad * 180 / 3.1415927f;
      int r = Color.red(color);
      int g = Color.green(color);
      int b = Color.blue(color);

      ColorMatrix cm = new ColorMatrix();
      ColorMatrix tmp = new ColorMatrix();

      cm.setRGB2YUV();
      tmp.setRotate(0, deg);
      cm.postConcat(tmp);
      tmp.setYUV2RGB();
      cm.postConcat(tmp);

      final float[] a = cm.getArray();

      int ir = floatToByte(a[0] * r + a[1] * g + a[2] * b);
      int ig = floatToByte(a[5] * r + a[6] * g + a[7] * b);
      int ib = floatToByte(a[10] * r + a[11] * g + a[12] * b);

      return Color.argb(
          Color.alpha(color), pinToByte(ir),
          pinToByte(ig), pinToByte(ib));
    }
 private int changeColorAlpha(int color, float value) {
   int alpha = Math.round(Color.alpha(color) * value);
   int red = Color.red(color);
   int green = Color.green(color);
   int blue = Color.blue(color);
   return Color.argb(alpha, red, green, blue);
 }
Пример #4
0
    private int interpColor(int colors[], float unit) {
      if (unit <= 0) {
        return colors[0];
      }
      if (unit >= 1) {
        return colors[colors.length - 1];
      }

      float p = unit * (colors.length - 1);
      int i = (int) p;
      p -= i;

      // now p is just the fractional part [0...1) and i is the index
      int c0 = colors[i];
      int c1 = colors[i + 1];
      int a = ave(Color.alpha(c0), Color.alpha(c1), p);
      int r = ave(Color.red(c0), Color.red(c1), p);
      int g = ave(Color.green(c0), Color.green(c1), p);
      int b = ave(Color.blue(c0), Color.blue(c1), p);

      return Color.argb(a, r, g, b);
    }