private void updateIndicator() { // M: Theme manager @{ if (FeatureOption.MTK_THEMEMANAGER_APP) { Resources res = getContext().getResources(); int themeColor = res.getThemeMainColor(); if (themeColor != 0) { mLeftColor = themeColor; mMiddleColor = themeColor; } } // M: Theme manager @} int off = getPaddingTop() - getPaddingBottom(); if (off < 0) off = 0; mRect.top = off; mRect.bottom = getHeight(); if (mShowingGreen) { mColorGradientPaint.setShader( new LinearGradient( 0, 0, 0, off - 2, mRightColor & 0xffffff, mRightColor, Shader.TileMode.CLAMP)); } else { mColorGradientPaint.setShader( new LinearGradient( 0, 0, 0, off - 2, mMiddleColor & 0xffffff, mMiddleColor, Shader.TileMode.CLAMP)); } mEdgeGradientPaint.setShader( new LinearGradient(0, 0, 0, off / 2, 0x00a0a0a0, 0xffa0a0a0, Shader.TileMode.CLAMP)); }
public void paintBitmap(Context context, Canvas c, Rect dest) { int color0 = Color.argb(0xFF, 196, 181, 51); int color1 = Color.argb(0xFF, 251, 219, 39); int color2 = Color.argb(0xFF, 255, 239, 151); int border = Color.argb(0xFF, 220, 200, 80); Paint p = new Paint(); p.setAntiAlias(true); float width = dest.width() / 20.0f; float insideSize = dest.width() - 2 * width; RectF inside1 = new RectF( dest.left + width - 1, dest.top + width - 1, dest.right - width + 1, dest.bottom - width + 1); RectF inside = new RectF(dest.left + width, dest.top + width, dest.right - width, dest.bottom - width); LinearGradient linear = new LinearGradient( inside1.left, inside1.top + insideSize / 3, inside1.right, inside1.top + 2 * insideSize / 3, new int[] {color0, color1, color2}, null, Shader.TileMode.CLAMP); p.setShader(linear); c.drawRoundRect(inside1, width, width, p); p.setShader(null); p.setColor(border); Path path = new Path(); path.addRoundRect(inside, width, width, Path.Direction.CCW); path.addRect(new RectF(dest), Path.Direction.CW); c.drawPath(path, p); }
public void updateColorRange() { if (OsmMapGpsTrailerReviewerMapActivity.prefs.colorRange.length > 1) { LinearGradient shader = new LinearGradient( 0, 0, MAX_SHADER_VALUE, 0, OsmMapGpsTrailerReviewerMapActivity.prefs.colorRange, null, Shader.TileMode.REPEAT); gradientPaint.setShader(shader); } else { gradientPaint.setShader(null); gradientPaint.setColor(OsmMapGpsTrailerReviewerMapActivity.prefs.colorRange[0]); } leftDPBarColor = new Paint(); leftDPBarColor.setColor(OsmMapGpsTrailerReviewerMapActivity.prefs.colorRange[0]); rightDPBarColor = new Paint(); rightDPBarColor.setColor( OsmMapGpsTrailerReviewerMapActivity.prefs .colorRange[OsmMapGpsTrailerReviewerMapActivity.prefs.colorRange.length - 1]); }
@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 void buildShadow() { if (mShadowSize <= 0) return; if (mShadowPaint == null) { mShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); mShadowPaint.setStyle(Paint.Style.FILL); mShadowPaint.setDither(true); } float startRatio = (float) mRadius / (mRadius + mShadowSize + mShadowOffset); mShadowPaint.setShader( new RadialGradient( 0, 0, mRadius + mShadowSize, new int[] {COLOR_SHADOW_START, COLOR_SHADOW_START, COLOR_SHADOW_END}, new float[] {0f, startRatio, 1f}, Shader.TileMode.CLAMP)); if (mShadowPath == null) { mShadowPath = new Path(); mShadowPath.setFillType(Path.FillType.EVEN_ODD); } else mShadowPath.reset(); float radius = mRadius + mShadowSize; mTempRect.set(-radius, -radius, radius, radius); mShadowPath.addOval(mTempRect, Path.Direction.CW); radius = mRadius - 1; mTempRect.set(-radius, -radius - mShadowOffset, radius, radius - mShadowOffset); mShadowPath.addOval(mTempRect, Path.Direction.CW); if (mGlowPaint == null) { mGlowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); mGlowPaint.setStyle(Paint.Style.FILL); mGlowPaint.setDither(true); } startRatio = (mRadius - mShadowSize / 2f) / (mRadius + mShadowSize / 2f); mGlowPaint.setShader( new RadialGradient( 0, 0, mRadius + mShadowSize / 2f, new int[] {COLOR_SHADOW_START, COLOR_SHADOW_START, COLOR_SHADOW_END}, new float[] {0f, startRatio, 1f}, Shader.TileMode.CLAMP)); if (mGlowPath == null) { mGlowPath = new Path(); mGlowPath.setFillType(Path.FillType.EVEN_ODD); } else mGlowPath.reset(); radius = mRadius + mShadowSize / 2f; mTempRect.set(-radius, -radius, radius, radius); mGlowPath.addOval(mTempRect, Path.Direction.CW); radius = mRadius - 1; mTempRect.set(-radius, -radius, radius, radius); mGlowPath.addOval(mTempRect, Path.Direction.CW); }
private void setCornerRadius(float paramFloat) { if (isGreaterThanZero(paramFloat)) { mPaint.setShader(mBitmapShader); } for (; ; ) { mCornerRadius = paramFloat; return; mPaint.setShader(null); } }
private void setup() { if (!mReady) { mSetupPending = true; return; } if (mBitmap == null) { return; } mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mBitmapPaint.setAntiAlias(true); mBitmapPaint.setShader(mBitmapShader); mBorderPaint.setStyle(Paint.Style.STROKE); mBorderPaint.setAntiAlias(true); mBorderPaint.setColor(mBorderColor); mBorderPaint.setStrokeWidth(mBorderWidth); mBitmapHeight = mBitmap.getHeight(); mBitmapWidth = mBitmap.getWidth(); mBorderRect.set(0, 0, getWidth(), getHeight()); mBorderRadius = Math.min( (mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2); mDrawableRect.set( mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth); mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2); mFlagBackgroundPaint.setColor(Color.BLACK & 0x66FFFFFF); mFlagBackgroundPaint.setFlags(TextPaint.ANTI_ALIAS_FLAG); mFlagTextPaint.setFlags(TextPaint.ANTI_ALIAS_FLAG); mFlagTextPaint.setTextAlign(Align.CENTER); mFlagTextPaint.setColor(Color.WHITE); mFlagTextPaint.setTextSize(getResources().getDisplayMetrics().density * 18); mSweepGradient = new SweepGradient( getWidth() / 2, getHeight() / 2, new int[] {Color.rgb(255, 255, 255), Color.rgb(1, 209, 255)}, null); mBorderPaint.setShader(mSweepGradient); updateShaderMatrix(); invalidate(); }
@Override public void onDraw(Canvas canvas) { mPaint.setShader(mShader); mPaint.setStyle(Paint.Style.FILL); int sc = canvas.save(); canvas.drawPath(mPath, mPaint); mPaint.setShader(null); mPaint.setStyle(Paint.Style.STROKE); canvas.drawPath(mPath, mPaint); canvas.restoreToCount(sc); canvas.clipPath(mPath); }
/** Sets the corner radius to be applied when drawing the bitmap. */ public void setCornerRadius(float cornerRadius) { if (mCornerRadius == cornerRadius) return; mIsCircular = false; if (isGreaterThanZero(cornerRadius)) { mPaint.setShader(mBitmapShader); } else { mPaint.setShader(null); } mCornerRadius = cornerRadius; invalidateSelf(); }
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); if (isCanvasRectEmpty()) { path = Optional.absent(); backgroundPaint.setShader(null); return; } path = Optional.of(pathFactory.newInstance(bounds)); backgroundPaint.setShader( new LinearGradient( 0, bounds.top, 0, bounds.bottom - 1, topColor, bottomColor, TileMode.CLAMP)); }
/** * 绘制自己 * * @param canvas * @param paint */ public void draw(Canvas canvas, Paint paint) { if (-x > mGameWidth) { x = x % mGameWidth; } canvas.save(Canvas.MATRIX_SAVE_FLAG); // 移动到指定位置 canvas.translate(x, y); paint.setShader(mFloorShader); // 这里mGameHeight-y计算出的是地板最后一个色素应该下下拉伸的距离 把-x+mGameWidth的值替换为720就能看出来这个的作用了 canvas.drawRect(x, 0, -x + mGameWidth, mGameHeight - y, paint); // Log.d(TAG, "draw: xis "+x+" -x+mGameWidth is " +((-x+mGameWidth)-x)); canvas.restore(); paint.setShader(null); }
private boolean doStroke(Properties atts, HashMap<String, Shader> gradients) { if (whiteMode) { // Never stroke in white mode return false; } if ("none".equals(atts.getString("display"))) { return false; } String strokeString = atts.getString("stroke"); if (strokeString == null) return false; if (strokeString.startsWith("url(#")) { String id = strokeString.substring("url(#".length(), strokeString.length() - 1); Shader shader = gradients.get(id); if (shader == null) return false; paint.setShader(shader); } else { Integer color = atts.getHex("stroke"); if (color == null) return false; paint.setShader(null); doColor(atts, color, false); } // Check for other stroke attributes Float width = atts.getFloat("stroke-width", true); // Set defaults if (width != null) { paint.setStrokeWidth(width); } String linecap = atts.getString("stroke-linecap"); if ("round".equals(linecap)) { paint.setStrokeCap(Paint.Cap.ROUND); } else if ("square".equals(linecap)) { paint.setStrokeCap(Paint.Cap.SQUARE); } else if ("butt".equals(linecap)) { paint.setStrokeCap(Paint.Cap.BUTT); } String linejoin = atts.getString("stroke-linejoin"); if ("miter".equals(linejoin)) { paint.setStrokeJoin(Paint.Join.MITER); } else if ("round".equals(linejoin)) { paint.setStrokeJoin(Paint.Join.ROUND); } else if ("bevel".equals(linejoin)) { paint.setStrokeJoin(Paint.Join.BEVEL); } paint.setStyle(Paint.Style.STROKE); return true; }
private void drawWave(Canvas canvas) { if (mState != STATE_OUT) { if (mState == STATE_RELEASE) { if (mRippleRadius == 0) { mFillPaint.setColor(mRippleColor); canvas.drawPath(mBackground, mFillPaint); } else { mShaderPaint.setShader(mOutShader); canvas.drawPath(mBackground, mShaderPaint); } } else if (mRippleRadius > 0) { mShaderPaint.setShader(mInShader); canvas.drawPath(mBackground, mShaderPaint); } } }
@Override public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBitmap != source) { source.recycle(); } if (source.getConfig() == null) { return source; } Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); squaredBitmap.recycle(); return bitmap; }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // 计算组件绘制区域的宽高 viewH = getHeight() - getPaddingLeft() - getPaddingRight(); viewW = getWidth() - getPaddingTop() - getPaddingBottom(); int bottom = viewH; // 计算view底部距离 count = viewW / (rectW + 10); // 计算矩形的个数 10位矩形的间距 Rect rectw = new Rect(0, 0, viewW, bottom); // 外边框矩形 canvas.drawRect(rectw, rectK); // 循环绘制矩形 for (int i = 0; i < count; i++) { linearGradient = new LinearGradient( 0, 0, rectW, randomH(), new int[] {Color.BLUE, Color.YELLOW, Color.CYAN, Color.GREEN}, new float[] {0.3f, 0.5f, 0.7f, 0.9f}, Shader.TileMode.CLAMP); rectP.setShader(linearGradient); Rect rect = new Rect( (int) (viewW * 0.03f + i * (rectW + 10)), bottom - randomH(), (int) (viewW * 0.03f + (i) * (rectW + 10) + rectW), bottom); canvas.drawRect(rect, rectP); } canvas.save(); postInvalidateDelayed(300); }
/** * Set the bar color. <br> * <br> * Its discouraged to use this method. * * @param color */ public void setColor(int color) { int x1, y1; if (mOrientation == ORIENTATION_HORIZONTAL) { x1 = (mBarLength + mBarPointerHaloRadius); y1 = mBarThickness; } else { x1 = mBarThickness; y1 = (mBarLength + mBarPointerHaloRadius); } Color.colorToHSV(color, mHSVColor); shader = new LinearGradient( mBarPointerHaloRadius, 0, x1, y1, new int[] {Color.HSVToColor(0x00, mHSVColor), color}, null, Shader.TileMode.CLAMP); mBarPaint.setShader(shader); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); }
private void initGame() { holder = getHolder(); holder.addCallback(this); // To store the initially colored shapes (Rect--> integer map) initiallyColoredShapes = new LinkedHashMap<>(); initiallyColoredShapes.clear(); // Default background color background = getResources().getColor(R.color.mondrian_background); // To store used colors (once) chosenColors = new HashSet<>(); chosenColors.clear(); // Lines are drawn in black with a stroke stroke = new Paint(); stroke.setAntiAlias(true); stroke.setStrokeWidth(getResources().getDimension(R.dimen.gv_line_width)); stroke.setColor(getResources().getColor(R.color.line_color)); stroke.setStyle(Paint.Style.STROKE); // The shapes are filled with colors fill = new Paint(); fill.setAntiAlias(true); fill.setStyle(Paint.Style.FILL); // To bring out adjacent shapes with the same color (game over) Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.game_over_stripes); BitmapShader bitmapshader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); // If you lose, shapes are drawn with striped lines striped = new Paint(); striped.setAntiAlias(true); striped.setStyle(Paint.Style.FILL); striped.setShader(bitmapshader); DEFAULT_BACKGROUND = getResources().getColor(R.color.mondrian_background); }
@Override public Bitmap transform(final Bitmap source) { final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); canvas.drawRoundRect( new RectF(0, 0, source.getWidth(), source.getHeight()), radius, radius, paint); if (source != output) { source.recycle(); } // Paint paint1 = new Paint(); // paint1.setColor(Color.RED); // paint1.setStyle(Style.STROKE); // paint1.setAntiAlias(true); // paint1.setStrokeWidth(2); // canvas.drawCircle((source.getWidth() - margin)/2, (source.getHeight() - margin)/2, // radius-2, paint1); return output; }
@Override public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBitmap != source) { source.recycle(); } Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig()); Canvas canvas = new Canvas(bitmap); Paint avatarPaint = new Paint(); BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); avatarPaint.setShader(shader); Paint outlinePaint = new Paint(); outlinePaint.setColor(Color.WHITE); outlinePaint.setStyle(Paint.Style.STROKE); outlinePaint.setStrokeWidth(STROKE_WIDTH); outlinePaint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, avatarPaint); canvas.drawCircle(r, r, r - STROKE_WIDTH / 2, outlinePaint); squaredBitmap.recycle(); return bitmap; }
@Override public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int width = (source.getWidth() - size) / 2; int height = (source.getHeight() - size) / 2; Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); BitmapShader shader = new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); if (width != 0 || height != 0) { // source isn't square, move viewport to center Matrix matrix = new Matrix(); matrix.setTranslate(-width, -height); shader.setLocalMatrix(matrix); } paint.setShader(shader); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); source.recycle(); return bitmap; }
private void setup() { // TODO Auto-generated method stub mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mPaint = new Paint(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); mPaint.setShader(mBitmapShader); }
public BezierCurveDrawable(Bitmap bitmap) { BitmapShader shader; shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); paint = new Paint(); paint.setAntiAlias(true); paint.setShader(shader); }
public Bitmap getReflectedBitmap(Bitmap bitmap) { // LogUtil.i("chenxu", "bitmap's width:"+bitmap.getWidth()+" height:"+bitmap.getHeight()+" // totalHeight:"+height); Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, itemWidth, height * 2 / 3, true); Bitmap resultBitmap = Bitmap.createBitmap(itemWidth, height, Config.ARGB_8888); Canvas canvas = new Canvas(resultBitmap); canvas.drawBitmap(scaledBitmap, null, new Rect(0, 0, itemWidth, height * 2 / 3), null); Paint paint = new Paint(); paint.setAntiAlias(true); LinearGradient shader = new LinearGradient(0, height * 2 / 3, 0, height, 0x88ffffff, 0xffffffff, TileMode.CLAMP); paint.setShader(shader); paint.setAlpha(180); Matrix matrix = new Matrix(); matrix.postScale(1, -1); Bitmap reflectionBitmap = Bitmap.createBitmap( scaledBitmap, 0, height * 2 / 3 * 2 / 3, itemWidth, height * 2 / 3 * 1 / 3, matrix, true); canvas.drawBitmap(reflectionBitmap, 0, height * 2 / 3, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); Rect r = new Rect(0, height * 2 / 3, 0, height); canvas.drawRect(r, paint); return resultBitmap; }
@Override public Bitmap transform(final Bitmap source) { final Paint shadowPaint = new Paint(); shadowPaint.setAntiAlias(true); shadowPaint.setShadowLayer(margin / 2, radius / 2, radius / 2, 0x30000000); Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); canvas.drawRoundRect( new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, shadowPaint); final Paint picPaint = new Paint(); picPaint.setAntiAlias(true); picPaint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); canvas.drawRoundRect( new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, picPaint); if (source != output) { source.recycle(); } return output; }
@SuppressLint("DrawAllocation") @Override public void onDraw(Canvas canvas) { // load the bitmap loadBitmap(); // init shader if (image != null) { shader = new BitmapShader( Bitmap.createScaledBitmap(image, canvas.getWidth(), canvas.getHeight(), false), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); paint.setShader(shader); int circleCenter = viewWidth / 2; // circleCenter is the x or y of the view's center // radius is the radius in pixels of the cirle to be drawn // paint contains the shader that will texture the shape canvas.drawCircle( circleCenter + borderWidth, circleCenter + borderWidth, circleCenter + borderWidth, paintBorder); canvas.drawCircle( circleCenter + borderWidth, circleCenter + borderWidth, circleCenter, paint); } }
public static Bitmap createReflectedImage(Bitmap bitmap, int i) { int j = bitmap.getWidth(); int k = bitmap.getHeight(); Bitmap bitmap2; if (k <= i) { bitmap2 = null; } else { Matrix matrix = new Matrix(); matrix.preScale(1.0F, -1F); Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, k - i, j, i, matrix, true); bitmap2 = Bitmap.createBitmap(j, i, android.graphics.Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap2); canvas.drawBitmap(bitmap1, 0.0F, 0.0F, null); LinearGradient lineargradient = new LinearGradient( 0.0F, 0.0F, 0.0F, bitmap2.getHeight(), -2130706433, 16777215, android.graphics.Shader.TileMode.CLAMP); Paint paint = new Paint(); paint.setShader(lineargradient); paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN)); canvas.drawRect(0.0F, 0.0F, j, bitmap2.getHeight(), paint); } return bitmap2; }
@Override public void onDraw(final Canvas c) { // Draw the alpha pattern mAlphaPattern.draw(c); // Draw the shader that shows how transparent a colors looks at a given alpha on top of the // alpha pattern shaderPaint.setShader( new LinearGradient( borderSize, 0, this.getWidth() - borderSize, 0, 0, color, TileMode.CLAMP)); c.drawRect( borderSize, borderSize, this.getWidth() - borderSize, this.getHeight() - borderSize, shaderPaint); // Draw the transparency label on top of that stuff c.drawText( "Transparency", this.getWidth() / 2, this.getHeight() / 2 + labelPaint.getTextSize() / 2.0f, labelPaint); // Draw the alpha tracker on top of everything else final float xPos = alphaToXPos(alpha); final float rectWidth = 2 * mDensity; final RectF r = new RectF(); r.left = xPos - rectWidth; r.right = xPos + rectWidth; r.top = 0; r.bottom = this.getHeight(); c.drawRoundRect(r, rectWidth, rectWidth, trackerPaint); }
private Bitmap createColorWheelBitmap(int width, int height) { Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); int colorCount = 12; int colorAngleStep = 360 / 12; int colors[] = new int[colorCount + 1]; float hsv[] = new float[] {0f, 1f, 1f}; for (int i = 0; i < colors.length; i++) { hsv[0] = (i * colorAngleStep + 180) % 360; colors[i] = Color.HSVToColor(hsv); } colors[colorCount] = colors[0]; SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null); RadialGradient radialGradient = new RadialGradient( width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP); ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER); colorWheelPaint.setShader(composeShader); Canvas canvas = new Canvas(bitmap); canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint); return bitmap; }
void updateDstRect() { if (mApplyGravity) { if (mIsCircular) { final int minDimen = Math.min(mBitmapWidth, mBitmapHeight); gravityCompatApply(mGravity, minDimen, minDimen, getBounds(), mDstRect); // inset the drawing rectangle to the largest contained square, // so that a circle will be drawn final int minDrawDimen = Math.min(mDstRect.width(), mDstRect.height()); final int insetX = Math.max(0, (mDstRect.width() - minDrawDimen) / 2); final int insetY = Math.max(0, (mDstRect.height() - minDrawDimen) / 2); mDstRect.inset(insetX, insetY); mCornerRadius = 0.5f * minDrawDimen; } else { gravityCompatApply(mGravity, mBitmapWidth, mBitmapHeight, getBounds(), mDstRect); } mDstRectF.set(mDstRect); if (mBitmapShader != null) { // setup shader matrix mShaderMatrix.setTranslate(mDstRectF.left, mDstRectF.top); mShaderMatrix.preScale( mDstRectF.width() / mBitmap.getWidth(), mDstRectF.height() / mBitmap.getHeight()); mBitmapShader.setLocalMatrix(mShaderMatrix); mPaint.setShader(mBitmapShader); } mApplyGravity = false; } }
@Override protected void onDraw(Canvas canvas) { // draw the background and color wheel canvas.drawBitmap(mBackground, mBackgroundPosition.x, mBackgroundPosition.y, null); canvas.drawBitmap(mWheel, mWheelPosition.x, mWheelPosition.y, null); // setup paint for the gradient filling Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.FILL); paint.setStrokeWidth(2.0f); // create a shader that will show the range of brightness settings float[] gradientStartColor = new float[3]; float[] gradientEndColor = new float[3]; System.arraycopy(mNewColor, 0, gradientStartColor, 0, mNewColor.length); System.arraycopy(mNewColor, 0, gradientEndColor, 0, mNewColor.length); gradientStartColor[2] = 1.0f; gradientEndColor[2] = 0.0f; Shader gradientShader = new LinearGradient( (float) (mWheelPosition.x + mRadius), mWheelPosition.y, mOuterArcRect.right, mWheelPosition.y + mWheel.getHeight(), Color.HSVToColor(gradientStartColor), Color.HSVToColor(gradientEndColor), Shader.TileMode.MIRROR); paint.setShader(gradientShader); canvas.drawPath(mArcPath, paint); drawHSCrosshairs(canvas); drawBrightnessIndicator(canvas); }