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; }
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 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); }
// 그리기 void Draw(Canvas canvas) { Paint pnt = new Paint(); pnt.setAntiAlias(true); int r; int alpha; for (r = rad, alpha = 1; r > 4; r--, alpha += 5) { pnt.setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))); canvas.drawCircle(x, y, r, pnt); } }
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); }
public static Bitmap blurBmp(Bitmap bmp, int Blur) { int pixels[] = new int[bmp.getWidth() * bmp.getHeight()]; int pixelsRawSource[] = new int[bmp.getWidth() * bmp.getHeight() * 3]; int pixelsRawNew[] = new int[bmp.getWidth() * bmp.getHeight() * 3]; bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight()); for (int k = 1; k <= Blur; k++) { for (int i = 0; i < pixels.length; i++) { pixelsRawSource[i * 3 + 0] = Color.red(pixels[i]); pixelsRawSource[i * 3 + 1] = Color.green(pixels[i]); pixelsRawSource[i * 3 + 2] = Color.blue(pixels[i]); } int CurrentPixel = bmp.getWidth() * 3 + 3; for (int i = 0; i < bmp.getHeight() - 3; i++) { for (int j = 0; j < bmp.getWidth() * 3; j++) { CurrentPixel += 1; int sumColor = 0; sumColor = pixelsRawSource[CurrentPixel - bmp.getWidth() * 3]; sumColor = sumColor + pixelsRawSource[CurrentPixel - 3]; sumColor = sumColor + pixelsRawSource[CurrentPixel + 3]; sumColor = sumColor + pixelsRawSource[CurrentPixel + bmp.getWidth() * 3]; pixelsRawNew[CurrentPixel] = Math.round(sumColor / 4); } } for (int i = 0; i < pixels.length; i++) { pixels[i] = Color.rgb(pixelsRawNew[i * 3 + 0], pixelsRawNew[i * 3 + 1], pixelsRawNew[i * 3 + 2]); } } Bitmap bmpReturn = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888); bmpReturn.setPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight()); return bmpReturn; }
private int getDarkerShade(int color) { return Color.rgb( (int) (SHADE_FACTOR * Color.red(color)), (int) (SHADE_FACTOR * Color.green(color)), (int) (SHADE_FACTOR * Color.blue(color))); }