Example #1
0
  public RuleAdapter(DatabaseHelper dh, Activity context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    this.context = context;
    this.dh = dh;
    this.filter = prefs.getBoolean("filter", false);
    this.debuggable = Util.isDebuggable(context);

    if (prefs.getBoolean("dark_theme", false))
      colorChanged =
          Color.argb(
              128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY), Color.blue(Color.DKGRAY));
    else
      colorChanged =
          Color.argb(
              128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY), Color.blue(Color.LTGRAY));

    TypedArray ta =
        context.getTheme().obtainStyledAttributes(new int[] {android.R.attr.textColorSecondary});
    try {
      colorText = ta.getColor(0, 0);
    } finally {
      ta.recycle();
    }

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorAccent, tv, true);
    colorAccent = tv.data;
    context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    colorOn = tv.data;
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    colorOff = tv.data;
  }
 /**
  * Blend {@code color1} and {@code color2} using the given ratio.
  *
  * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
  *     0.0 will return {@code color2}.
  */
 private static int blendColors(int color1, int color2, float ratio) {
   final float inverseRation = 1f - ratio;
   float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
   float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
   float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
   return Color.rgb((int) r, (int) g, (int) b);
 }
  @Override
  public void onColorChanged(int color) {
    picker.setOldCenterColor(picker.getColor());
    picker2.setOldCenterColor(picker2.getColor());
    refreshBackgroundColors();

    if (!requestPending) {
      requestPending = true;
      AsyncHttpClient client = new AsyncHttpClient();
      client.get(
          SettingsFragment.ip
              + "color?color&"
              + colorToString(Color.red(picker.getColor()) * getAlpha(picker.getColor()))
              + "&"
              + colorToString(Color.green(picker.getColor()) * getAlpha(picker.getColor()))
              + "&"
              + colorToString(Color.blue(picker.getColor()) * getAlpha(picker.getColor()))
              + "&"
              + colorToString(Color.red(picker2.getColor()) * getAlpha(picker2.getColor()))
              + "&"
              + colorToString(Color.green(picker2.getColor()) * getAlpha(picker2.getColor()))
              + "&"
              + colorToString(Color.blue(picker2.getColor()) * getAlpha(picker2.getColor()))
              + "",
          new AsyncHttpResponseHandler() {
            @Override
            public void onFinish() {
              requestPending = false;
            }
          });
    }
  }
  public int getColor(float position) {
    int color1 = colors[0];
    int color2 = colors[0];
    float position1 = 0.0f;
    float position2 = 0.0f;

    for (int i = 0; i < positions.length; i++) {
      position1 = position2;
      position2 = positions[i];
      color1 = color2;
      color2 = colors[i];
      if (position2 > position) {
        break;
      }
    }

    if (position > position2) {
      return color2;
    }

    float ratio = (position - position1) / (position2 - position1);
    return Color.rgb(
        (int) (Color.red(color1) * (1 - ratio) + Color.red(color2) * ratio),
        (int) (Color.green(color1) * (1 - ratio) + Color.green(color2) * ratio),
        (int) (Color.blue(color1) * (1 - ratio) + Color.blue(color2) * ratio));
  }
Example #5
0
 private void onColorChange() {
   nextColor = thisColor + 1;
   nextColor %= colors.length;
   red = (Color.red(colors[nextColor]) - Color.red(colors[thisColor])) * 1.0 / speed;
   green = (Color.green(colors[nextColor]) - Color.green(colors[thisColor])) * 1.0 / speed;
   blue = (Color.blue(colors[nextColor]) - Color.blue(colors[thisColor])) * 1.0 / speed;
 }
Example #6
0
  private Item createItem(String label, float percent, int sliceColor, int itemColor) {
    Item it = new Item();
    it.mLabel = label;
    it.mItemColor = itemColor;
    it.cSliceColor = sliceColor;
    it.cPercent = percent;
    //        Log.d(TAG, "Percent for "+it.mLabel+": "+it.cPercent);

    // Calculate the highlight color. Saturate at 0xff to make sure that high values
    // don't result in aliasing.
    it.mItemHighlight =
        Color.argb(
            0xff,
            Math.min((int) (mHighlightStrength * (float) Color.red(itemColor)), 0xff),
            Math.min((int) (mHighlightStrength * (float) Color.green(itemColor)), 0xff),
            Math.min((int) (mHighlightStrength * (float) Color.blue(itemColor)), 0xff));

    it.cSliceHighlight =
        Color.argb(
            0xff,
            Math.min((int) (mHighlightStrength * (float) Color.red(sliceColor)), 0xff),
            Math.min((int) (mHighlightStrength * (float) Color.green(sliceColor)), 0xff),
            Math.min((int) (mHighlightStrength * (float) Color.blue(sliceColor)), 0xff));

    float centerX = mPieBounds.width() / 2;
    float centerY = mPieBounds.height() / 2;
    float itemW = (mPieBounds.width() / 2) * it.cPercent;
    float itemH = (mPieBounds.height() / 2) * it.cPercent;
    it.cSliceBounds = new RectF(centerX - itemW, centerY - itemH, centerX + itemW, centerY + itemH);

    return it;
  }
  public ColorItemsAdapter(Context context, int numberOfItems) {
    mColors = new int[numberOfItems];

    int startColor = context.getResources().getColor(R.color.wisteria);
    int startR = Color.red(startColor);
    int startG = Color.green(startColor);
    int startB = Color.blue(startColor);

    int endColor = context.getResources().getColor(R.color.emerald);
    int endR = Color.red(endColor);
    int endG = Color.green(endColor);
    int endB = Color.blue(endColor);

    ValueInterpolator interpolatorR = new ValueInterpolator(0, numberOfItems - 1, endR, startR);
    ValueInterpolator interpolatorG = new ValueInterpolator(0, numberOfItems - 1, endG, startG);
    ValueInterpolator interpolatorB = new ValueInterpolator(0, numberOfItems - 1, endB, startB);

    for (int i = 0; i < numberOfItems; ++i) {
      mColors[i] =
          Color.argb(
              255,
              (int) interpolatorR.map(i),
              (int) interpolatorG.map(i),
              (int) interpolatorB.map(i));
    }
  }
Example #8
0
  public String getLayoutColorNoBottoms(Bitmap image1, Bitmap image3) {
    String color = "";
    int red = 0;
    int blue = 0;
    int green = 0;
    int count = 0;
    for (int i = 145; i < 155; i++) {
      for (int k = 250; k < 280; k++) {
        int pixel = image1.getPixel(i, k);
        red += Color.red(pixel);
        blue += Color.blue(pixel);
        green += Color.green(pixel);
        count++;
      }
    }

    for (int i = 110; i < 125; i++) {
      for (int k = 250; k < 265; k++) {
        int pixel = image3.getPixel(i, k);
        red += Color.red(pixel);
        blue += Color.blue(pixel);
        green += Color.green(pixel);
        count++;
      }
    }
    red = (red / count);
    green = (green / count);
    blue = (blue / count);

    color = String.format("#%02x%02x%02x", red, green, blue);
    return color;
  }
Example #9
0
 public static boolean isLight(int color) {
   return Math.sqrt(
           Color.red(color) * Color.red(color) * .241
               + Color.green(color) * Color.green(color) * .691
               + Color.blue(color) * Color.blue(color) * .068)
       > 130;
 }
  public boolean equals(SgnColor o, int tolerance) {

    if (this == o) return true;

    if (o == null) return false;

    if (mColor == o.mColor) {
      return true;
    }

    if (tolerance == 0) {
      return false;
    }

    int r1 = Color.red(mColor);
    int g1 = Color.green(mColor);
    int b1 = Color.blue(mColor);
    int a1 = Color.alpha(mColor);

    int r2 = Color.red(o.mColor);
    int g2 = Color.green(o.mColor);
    int b2 = Color.blue(o.mColor);
    int a2 = Color.alpha(o.mColor);

    return Math.abs(r1 - r2) <= tolerance
        && Math.abs(g1 - g2) <= tolerance
        && Math.abs(b1 - b2) <= tolerance
        && Math.abs(a1 - a2) <= tolerance;
  }
Example #11
0
  /** @param value */
  private void calculateEffect(final double value) {
    final float mapToggleX =
        (float) SpringUtil.mapValueFromRangeToRange(value, 0, 1, spotMinX, spotMaxX);
    spotX = mapToggleX;

    float mapOffLineWidth =
        (float) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, 10, spotSize);

    offLineWidth = mapOffLineWidth;

    final int fb = Color.blue(onColor);
    final int fr = Color.red(onColor);
    final int fg = Color.green(onColor);

    final int tb = Color.blue(offBorderColor);
    final int tr = Color.red(offBorderColor);
    final int tg = Color.green(offBorderColor);

    int sb = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fb, tb);
    int sr = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fr, tr);
    int sg = (int) SpringUtil.mapValueFromRangeToRange(1 - value, 0, 1, fg, tg);

    sb = clamp(sb, 0, 255);
    sr = clamp(sr, 0, 255);
    sg = clamp(sg, 0, 255);

    borderColor = Color.rgb(sr, sg, sb);

    postInvalidate();
  }
Example #12
0
  /**
   * Calculate the color using the supplied angle.
   *
   * @param angle The selected color's position expressed as angle (in rad).
   * @return The ARGB value of the color on the color wheel at the specified angle.
   */
  private int calculateColor(float angle) {
    float unit = (float) (angle / (2 * Math.PI));
    if (unit < 0) {
      unit += 1;
    }

    if (unit <= 0) {
      mColor = COLORS[0];
      return COLORS[0];
    }
    if (unit >= 1) {
      mColor = COLORS[COLORS.length - 1];
      return COLORS[COLORS.length - 1];
    }

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

    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);

    mColor = Color.argb(a, r, g, b);
    return Color.argb(a, r, g, b);
  }
    @Override
    protected void onDraw(Canvas canvas) {
      int translatedHue = 255 - (int) (mCurrentHue * 255 / 360);
      // Display all the colors of the hue bar with lines
      for (int x = 0; x < 256; x++) {
        // If this is not the current selected hue, display the actual color
        if (translatedHue != x) {
          mPaint.setColor(mHueBarColors[x]);
          mPaint.setStrokeWidth(1);
        } else // else display a slightly larger black line
        {
          mPaint.setColor(Color.BLACK);
          mPaint.setStrokeWidth(3);
        }
        canvas.drawLine(x + 10, 0, x + 10, 40, mPaint);
      }

      // Display the main field colors using LinearGradient
      for (int x = 0; x < 256; x++) {
        int[] colors = new int[2];
        colors[0] = mMainColors[x];
        colors[1] = Color.BLACK;
        Shader shader = new LinearGradient(0, 50, 0, 306, colors, null, Shader.TileMode.REPEAT);
        mPaint.setShader(shader);
        canvas.drawLine(x + 10, 50, x + 10, 306, mPaint);
      }
      mPaint.setShader(null);

      // Display the circle around the currently selected color in the main field
      if (mCurrentX != 0 && mCurrentY != 0) {
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.BLACK);
        canvas.drawCircle(mCurrentX, mCurrentY, 10, mPaint);
      }

      // Draw a 'button' with the currently selected color
      mPaint.setStyle(Paint.Style.FILL);
      mPaint.setColor(mCurrentColor);
      canvas.drawRect(10, 316, 138, 356, mPaint);

      // Set the text color according to the brightness of the color
      if (Color.red(mCurrentColor) + Color.green(mCurrentColor) + Color.blue(mCurrentColor) < 384)
        mPaint.setColor(Color.WHITE);
      else mPaint.setColor(Color.BLACK);
      // canvas.drawText(getResources().getString(R.string.settings_bg_color_confirm), 74, 340,
      // mPaint);

      // Draw a 'button' with the default color
      mPaint.setStyle(Paint.Style.FILL);
      mPaint.setColor(mDefaultColor);
      canvas.drawRect(138, 316, 266, 356, mPaint);

      // Set the text color according to the brightness of the color
      if (Color.red(mDefaultColor) + Color.green(mDefaultColor) + Color.blue(mDefaultColor) < 384)
        mPaint.setColor(Color.WHITE);
      else mPaint.setColor(Color.BLACK);
      // canvas.drawText(getResources().getString(R.string.settings_default_color_confirm), 202,
      // 340, mPaint);
    }
 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);
 }
 private int sqrtMix(int colorOne, int colorTwo) {
   int result =
       Color.rgb(
           mixChannel(Color.red(colorOne), Color.red(colorTwo)),
           mixChannel(Color.green(colorOne), Color.green(colorTwo)),
           mixChannel(Color.blue(colorOne), Color.blue(colorTwo)));
   return result;
 }
Example #16
0
 protected int getGradientPartialColor(int minColor, int maxColor, float fraction) {
   int alpha =
       Math.round(fraction * Color.alpha(minColor) + (1 - fraction) * Color.alpha(maxColor));
   int r = Math.round(fraction * Color.red(minColor) + (1 - fraction) * Color.red(maxColor));
   int g = Math.round(fraction * Color.green(minColor) + (1 - fraction) * Color.green(maxColor));
   int b = Math.round(fraction * Color.blue(minColor) + (1 - fraction) * Color.blue((maxColor)));
   return Color.argb(alpha, r, g, b);
 }
  /** Return a {@link Color} that is (1-p) like {@code from} and p like {@code to}. */
  public static int blend(int from, int to, float weigh) {
    int a = (int) ((1 - weigh) * Color.alpha(from) + weigh * Color.alpha(to));
    int r = (int) ((1 - weigh) * Color.red(from) + weigh * Color.red(to));
    int g = (int) ((1 - weigh) * Color.green(from) + weigh * Color.green(to));
    int b = (int) ((1 - weigh) * Color.blue(from) + weigh * Color.blue(to));

    return Color.argb(a, r, g, b);
  }
 public static int getMiddleColor(int prevColor, int curColor, float factor) {
   if (prevColor == curColor) return curColor;
   if (factor == 0f) return prevColor;
   else if (factor == 1f) return curColor;
   int a = getMiddleValue(Color.alpha(prevColor), Color.alpha(curColor), factor);
   int r = getMiddleValue(Color.red(prevColor), Color.red(curColor), factor);
   int g = getMiddleValue(Color.green(prevColor), Color.green(curColor), factor);
   int b = getMiddleValue(Color.blue(prevColor), Color.blue(curColor), factor);
   return Color.argb(a, r, g, b);
 }
Example #19
0
  /**
   * @param from color value in the form 0xAARRGGBB.
   * @param to color value in the form 0xAARRGGBB.
   */
  public static int getGradientColor(int from, int to, float factor) {
    int r =
        calculateGradient(
            Color.red(from), Color.red(to), factor); // It's so annoying without lambda.
    int g = calculateGradient(Color.green(from), Color.green(to), factor);
    int b = calculateGradient(Color.blue(from), Color.blue(to), factor);
    int a = calculateGradient(Color.alpha(from), Color.alpha(to), factor);

    return Color.argb(a, r, g, b);
  }
Example #20
0
 @ColorInt
 private static int blendColors(
     @ColorInt int color1, @ColorInt int color2, @FloatRange(from = 0f, to = 1f) float ratio) {
   final float inverseRatio = 1f - ratio;
   float a = (Color.alpha(color1) * inverseRatio) + (Color.alpha(color2) * ratio);
   float r = (Color.red(color1) * inverseRatio) + (Color.red(color2) * ratio);
   float g = (Color.green(color1) * inverseRatio) + (Color.green(color2) * ratio);
   float b = (Color.blue(color1) * inverseRatio) + (Color.blue(color2) * ratio);
   return Color.argb((int) a, (int) r, (int) g, (int) b);
 }
 private static final double colorDistance(int color1, int color2) {
   int redDistance = Color.red(color1) - Color.red(color2);
   int greenDistance = Color.green(color1) - Color.green(color2);
   int blueDistance = Color.blue(color1) - Color.blue(color2);
   double distance =
       Math.sqrt(
           redDistance * redDistance
               + greenDistance * greenDistance
               + blueDistance * blueDistance);
   return distance / 256.;
 }
Example #22
0
  /** Composite two potentially translucent colors over each other and returns the result. */
  public static int compositeColors(int foreground, int background) {
    final float alpha1 = Color.alpha(foreground) / 255f;
    final float alpha2 = Color.alpha(background) / 255f;

    float a = (alpha1 + alpha2) * (1f - alpha1);
    float r = (Color.red(foreground) * alpha1) + (Color.red(background) * alpha2 * (1f - alpha1));
    float g =
        (Color.green(foreground) * alpha1) + (Color.green(background) * alpha2 * (1f - alpha1));
    float b = (Color.blue(foreground) * alpha1) + (Color.blue(background) * alpha2 * (1f - alpha1));

    return Color.argb((int) a, (int) r, (int) g, (int) b);
  }
Example #23
0
  public static Bitmap getChromakey(Context c) {
    Bitmap chroma = BitmapFactory.decodeResource(c.getResources(), R.drawable.test_chromakey);
    Bitmap bg = BitmapFactory.decodeResource(c.getResources(), R.drawable.landscape1);

    Bitmap composite = Bitmap.createBitmap(bg.getWidth(), bg.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(composite);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    // canvas.drawBitmap(bg, 0, 0, paint);
    // Slow method: scan all input (layer) image pixels and corresponding background pixels.
    // Calculate its "greenness" and translucency and recreate the pixels' values, plotting
    // them over the background.
    int bgPixel, lPixel;
    float targetHue = 97f / 360f;
    float tolerance = 0.1f;
    int bgRed, bgGreen, bgBlue, lRed, lGreen, lBlue, oRed, oGreen, oBlue;
    for (int w = 0; w < bg.getWidth(); w++)
      for (int h = 0; h < bg.getHeight(); h++) {
        // Background pixels.
        bgPixel = bg.getPixel(w, h);
        bgRed = Color.red(bgPixel); // Red level
        bgGreen = Color.green(bgPixel); // Green level
        bgBlue = Color.blue(bgPixel); // Blue level
        // Layer pixels.
        lPixel = chroma.getPixel(w, h);
        lRed = Color.red(lPixel); // Red level
        lGreen = Color.green(lPixel); // Green level
        lBlue = Color.blue(lPixel); // Blue level
        float[] lHSB = new float[3];

        Color.RGBToHSV(lRed, lGreen, lBlue, lHSB);
        // Calculate the translucency, based on the green value of the layer, using HSB coordinates.
        // To make calculations easier, let's assume that the translucency is a value between 0
        // (invisible) and 1 (opaque).
        float deltaHue = Math.abs((lHSB[0] / 360) - targetHue);
        float translucency = (deltaHue / tolerance);
        translucency = Math.min(translucency, 1f);
        // Recalculate the RGB coordinates of the layer and background pixels, using the
        // translucency
        // as a weight.
        oRed = (int) (translucency * lRed + (1 - translucency) * bgRed);
        oGreen = (int) (translucency * lGreen + (1 - translucency) * bgGreen);
        oBlue = (int) (translucency * lBlue + (1 - translucency) * bgBlue);
        // Set the pixel on the output image's raster.
        // raster.setPixel(w+shiftX,h+shiftY,new int[]{oRed,oGreen,oBlue,255});
        paint = new Paint();
        paint.setColor(Color.rgb(oRed, oGreen, oBlue));
        canvas.drawPoint(w, h, paint);
      } // end for
    return composite;
  }
 private int getInverseColor(int color) {
   int red = Color.red(color);
   int green = Color.green(color);
   int blue = Color.blue(color);
   int alpha = Color.alpha(color);
   return Color.argb(alpha, 255 - red, 255 - green, 255 - blue);
 }
Example #25
0
  public static Bitmap doColorFilter(Bitmap src, double red, double green, double blue) {
    // image size
    int width = src.getWidth();
    int height = src.getHeight();
    // create output bitmap
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
    // color information
    int A, R, G, B;
    int pixel;

    // scan through all pixels
    for (int x = 0; x < width; ++x) {
      for (int y = 0; y < height; ++y) {
        // get pixel color
        pixel = src.getPixel(x, y);
        // apply filtering on each channel R, G, B
        A = Color.alpha(pixel);
        R = (int) (Color.red(pixel) * red);
        G = (int) (Color.green(pixel) * green);
        B = (int) (Color.blue(pixel) * blue);
        // set new color pixel to output bitmap
        bmOut.setPixel(x, y, Color.argb(A, R, G, B));
      }
    }

    // return final image
    return bmOut;
  }
Example #26
0
  @Override
  public synchronized void onDrawFrame(GL10 gl) {

    mObserver.onDrawFrame();

    if (mBackgroundColorChanged) {
      gl.glClearColor(
          Color.red(mBackgroundColor) / 255f,
          Color.green(mBackgroundColor) / 255f,
          Color.blue(mBackgroundColor) / 255f,
          Color.alpha(mBackgroundColor) / 255f);
      mBackgroundColorChanged = false;
    }

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();

    if (USE_PERSPECTIVE_PROJECTION) {
      gl.glTranslatef(0, 0, -6f);
    }

    for (int i = 0; i < mCurlMeshes.size(); ++i) {
      mCurlMeshes.get(i).draw(gl);
    }
  }
 private static JSONObject serializeColor(int color) throws JSONException {
   JSONObject jColor = new JSONObject();
   jColor.put("r", Color.red(color));
   jColor.put("g", Color.green(color));
   jColor.put("b", Color.blue(color));
   return jColor;
 }
Example #28
0
 /**
  * Sets the background color of the scene.
  *
  * @param color Android color integer.
  */
 public void setBackgroundColor(int color) {
   setBackgroundColor(
       Color.red(color) / 255f,
       Color.green(color) / 255f,
       Color.blue(color) / 255f,
       Color.alpha(color) / 255f);
 }
  /**
   * Get the white icon corresponding to a poiType.
   *
   * @param poiType the PoiType or null for notes.
   * @return The white icon.
   */
  public Drawable getIconWhite(PoiType poiType) {
    Bitmap myBitmap =
        BitmapFactory.decodeResource(
            context.getResources(),
            poiType == null ? R.drawable.open_book : getIconDrawableId(poiType));
    myBitmap = myBitmap.copy(myBitmap.getConfig(), true);

    int[] allpixels = new int[myBitmap.getHeight() * myBitmap.getWidth()];

    myBitmap.getPixels(
        allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());

    for (int i = 0; i < myBitmap.getHeight() * myBitmap.getWidth(); i++) {
      if (allpixels[i] != 0) {
        int A = Color.alpha(allpixels[i]);
        // inverting byte for each R/G/B channel
        int R = 255 - Color.red(allpixels[i]);
        int G = 255 - Color.green(allpixels[i]);
        int B = 255 - Color.blue(allpixels[i]);
        // set newly-inverted pixel to output image
        allpixels[i] = Color.argb(A, R, G, B);
      }
    }

    myBitmap.setPixels(
        allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());

    return new BitmapDrawable(context.getResources(), myBitmap);
  }
    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));
    }