android.graphics.ComposeShader Java Examples
The following examples show how to use
android.graphics.ComposeShader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ColorWheelView.java From SimpleDialogFragments with Apache License 2.0 | 6 votes |
protected void updateColorDependant(boolean hsvChanged, boolean hueChanged){ if (hueChanged) { Shader base = new LinearGradient(A.x, A.y, (B.x + C.x) / 2, (B.y + C.y) / 2, Color.HSVToColor(new float[]{mColor.hue(), 1, 1}), Color.BLACK, Shader.TileMode.CLAMP); Shader light = new LinearGradient((A.x + C.x) / 2, (A.y + C.y) / 2, B.x, B.y, Color.BLACK, Color.WHITE, Shader.TileMode.CLAMP); Shader both = new ComposeShader(base, light, PorterDuff.Mode.ADD); paint.setShader(both); } if (hsvChanged) { dotPaint.setColor(mColor.inverted().rgb()); dot = new PointF( C.x + (B.x - C.x + (A.x - B.x) * mColor.sat()) * mColor.val(), C.y + (B.y - C.y + (A.y - B.y) * mColor.sat()) * mColor.val()); } }
Example #2
Source File: ColorPicker.java From Mi-Band with GNU General Public License v2.0 | 6 votes |
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; }
Example #3
Source File: ColorPicker.java From redalert-android with Apache License 2.0 | 6 votes |
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; }
Example #4
Source File: ColorWheelView.java From SimpleDialogFragments with Apache License 2.0 | 6 votes |
protected void updateColorDependant(boolean hsvChanged, boolean hueChanged){ if (hueChanged) { Shader base = new LinearGradient(A.x, A.y, (B.x + C.x) / 2, (B.y + C.y) / 2, Color.HSVToColor(new float[]{mColor.hue(), 1, 1}), Color.BLACK, Shader.TileMode.CLAMP); Shader light = new LinearGradient((A.x + C.x) / 2, (A.y + C.y) / 2, B.x, B.y, Color.BLACK, Color.WHITE, Shader.TileMode.CLAMP); Shader both = new ComposeShader(base, light, PorterDuff.Mode.ADD); paint.setShader(both); } if (hsvChanged) { dotPaint.setColor(mColor.inverted().rgb()); dot = new PointF( C.x + (B.x - C.x + (A.x - B.x) * mColor.sat()) * mColor.val(), C.y + (B.y - C.y + (A.y - B.y) * mColor.sat()) * mColor.val()); } }
Example #5
Source File: ThemeEditorView.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private Bitmap createColorWheelBitmap(int width, int height) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); int colorCount = 12; int colorAngleStep = 360 / 12; int[] colors = new int[colorCount + 1]; float[] hsv = new float[]{0.0f, 1.0f, 1.0f}; 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, Shader.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; }
Example #6
Source File: StreamActivity.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); mRect.set(mMargin, mMargin, bounds.width() - mMargin, bounds.height() - mMargin); if (USE_VIGNETTE) { RadialGradient vignette = new RadialGradient( mRect.centerX(), mRect.centerY() * 1.0f / 0.7f, mRect.centerX() * 1.3f, new int[] { 0, 0, 0x7f000000 }, new float[] { 0.0f, 0.7f, 1.0f }, Shader.TileMode.CLAMP); Matrix oval = new Matrix(); oval.setScale(1.0f, 0.7f); vignette.setLocalMatrix(oval); mPaint.setShader( new ComposeShader(mBitmapShader, vignette, PorterDuff.Mode.SRC_OVER)); } }
Example #7
Source File: ColorPicker.java From Android-Color-Picker with Apache License 2.0 | 6 votes |
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; }
Example #8
Source File: ColorPicker.java From px-android with MIT License | 6 votes |
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[] = { 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; }
Example #9
Source File: MultiColorPicker.java From Android-Color-Picker with Apache License 2.0 | 6 votes |
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; }
Example #10
Source File: ThemeEditorView.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private Bitmap createColorWheelBitmap(int width, int height) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); int colorCount = 12; int colorAngleStep = 360 / 12; int colors[] = new int[colorCount + 1]; float hsv[] = new float[] { 0.0f, 1.0f, 1.0f }; 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, Shader.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; }
Example #11
Source File: ThemeEditorView.java From Telegram with GNU General Public License v2.0 | 6 votes |
private Bitmap createColorWheelBitmap(int width, int height) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); int colorCount = 12; int colorAngleStep = 360 / 12; int[] colors = new int[colorCount + 1]; float[] hsv = new float[]{0.0f, 1.0f, 1.0f}; 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, Shader.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; }
Example #12
Source File: ThemeEditorView.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private Bitmap createColorWheelBitmap(int width, int height) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); int colorCount = 12; int colorAngleStep = 360 / 12; int colors[] = new int[colorCount + 1]; float hsv[] = new float[] { 0.0f, 1.0f, 1.0f }; 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, Shader.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; }
Example #13
Source File: AmbilWarnaKotak.java From callmeter with GNU General Public License v3.0 | 6 votes |
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); if (this.paint == null) { this.paint = new Paint(); this.luar = new LinearGradient(0.f, 0.f, 0.f, this.ukuranUiPx, 0xffffffff, 0xff000000, TileMode.CLAMP); } this.tmp00[1] = this.tmp00[2] = 1.f; this.tmp00[0] = this.hue; int rgb = Color.HSVToColor(this.tmp00); this.dalam = new LinearGradient(0.f, 0.f, this.ukuranUiPx, 0.f, 0xffffffff, rgb, TileMode.CLAMP); ComposeShader shader = new ComposeShader(this.luar, this.dalam, PorterDuff.Mode.MULTIPLY); this.paint.setShader(shader); canvas.drawRect(0.f, 0.f, this.ukuranUiPx, this.ukuranUiPx, this.paint); }
Example #14
Source File: ColorPicker.java From SystemBarTint with Apache License 2.0 | 6 votes |
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; }
Example #15
Source File: MasterPaintView.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
public void drawComposeShader(PorterDuff.Mode mode) { Shader bitmapShader1 = new BitmapShader(cover, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Shader bitmapShader2 = new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Shader mShader = new ComposeShader(bitmapShader1, bitmapShader2, mode); reDraw(mShader); }
Example #16
Source File: ColorPicker.java From Telegram with GNU General Public License v2.0 | 5 votes |
private Bitmap createColorWheelBitmap(int width, int height) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); LinearGradient gradientShader = new LinearGradient(0, 0, width, 0, new int[]{Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.RED}, null, Shader.TileMode.CLAMP); LinearGradient alphaShader = new LinearGradient(0, (height / 3), 0, height, new int[]{Color.WHITE, Color.TRANSPARENT}, null, Shader.TileMode.CLAMP); ComposeShader composeShader = new ComposeShader(alphaShader, gradientShader, PorterDuff.Mode.MULTIPLY); colorWheelPaint.setShader(composeShader); Canvas canvas = new Canvas(bitmap); canvas.drawRect(0, 0, width, height, colorWheelPaint); return bitmap; }
Example #17
Source File: ColorPickerView.java From fanfouapp-opensource with Apache License 2.0 | 5 votes |
private void drawSatValPanel(final Canvas canvas) { final RectF rect = this.mSatValRect; if (ColorPickerView.BORDER_WIDTH_PX > 0) { this.mBorderPaint.setColor(this.mBorderColor); canvas.drawRect(this.mDrawingRect.left, this.mDrawingRect.top, rect.right + ColorPickerView.BORDER_WIDTH_PX, rect.bottom + ColorPickerView.BORDER_WIDTH_PX, this.mBorderPaint); } if (this.mValShader == null) { this.mValShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, 0xffffffff, 0xff000000, TileMode.CLAMP); } final int rgb = Color.HSVToColor(new float[] { this.mHue, 1f, 1f }); this.mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, 0xffffffff, rgb, TileMode.CLAMP); final ComposeShader mShader = new ComposeShader(this.mValShader, this.mSatShader, PorterDuff.Mode.MULTIPLY); this.mSatValPaint.setShader(mShader); canvas.drawRect(rect, this.mSatValPaint); final Point p = satValToPoint(this.mSat, this.mVal); this.mSatValTrackerPaint.setColor(0xff000000); canvas.drawCircle(p.x, p.y, this.PALETTE_CIRCLE_TRACKER_RADIUS - (1f * this.mDensity), this.mSatValTrackerPaint); this.mSatValTrackerPaint.setColor(0xffdddddd); canvas.drawCircle(p.x, p.y, this.PALETTE_CIRCLE_TRACKER_RADIUS, this.mSatValTrackerPaint); }
Example #18
Source File: ColorPicker.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private Bitmap createColorWheelBitmap(int width, int height) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); LinearGradient gradientShader = new LinearGradient(0, 0, width, 0, new int[]{Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.RED}, null, Shader.TileMode.CLAMP); LinearGradient alphaShader = new LinearGradient(0, (height / 3), 0, height, new int[]{Color.WHITE, Color.TRANSPARENT}, null, Shader.TileMode.CLAMP); ComposeShader composeShader = new ComposeShader(alphaShader, gradientShader, PorterDuff.Mode.MULTIPLY); colorWheelPaint.setShader(composeShader); Canvas canvas = new Canvas(bitmap); canvas.drawRect(0, 0, width, height, colorWheelPaint); return bitmap; }
Example #19
Source File: RoundedVignetteBitmapDisplayer.java From WliveTV with Apache License 2.0 | 5 votes |
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); RadialGradient vignette = new RadialGradient( mRect.centerX(), mRect.centerY() * 1.0f / 0.7f, mRect.centerX() * 1.3f, new int[]{0, 0, 0x7f000000}, new float[]{0.0f, 0.7f, 1.0f}, Shader.TileMode.CLAMP); Matrix oval = new Matrix(); oval.setScale(1.0f, 0.7f); vignette.setLocalMatrix(oval); paint.setShader(new ComposeShader(bitmapShader, vignette, PorterDuff.Mode.SRC_OVER)); }
Example #20
Source File: RoundedVignetteBitmapDisplayer.java From candybar with Apache License 2.0 | 5 votes |
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); RadialGradient vignette = new RadialGradient( mRect.centerX(), mRect.centerY() * 1.0f / 0.7f, mRect.centerX() * 1.3f, new int[]{0, 0, 0x7f000000}, new float[]{0.0f, 0.7f, 1.0f}, Shader.TileMode.CLAMP); Matrix oval = new Matrix(); oval.setScale(1.0f, 0.7f); vignette.setLocalMatrix(oval); paint.setShader(new ComposeShader(bitmapShader, vignette, PorterDuff.Mode.SRC_OVER)); }
Example #21
Source File: RoundedLomoBitmapDisplayer.java From Android-Application-ZJB with Apache License 2.0 | 5 votes |
protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); RadialGradient vignette = new RadialGradient(this.mRect.centerX(), this.mRect.centerY() * 1.0F / 0.7F, this.mRect.centerX() * 1.3F, new int[]{0, 0, 2130706432}, new float[]{0.0F, 0.7F, 1.0F}, TileMode.CLAMP); Matrix oval = new Matrix(); oval.setScale(1.0F, 0.7F); vignette.setLocalMatrix(oval); this.paint.setShader(new ComposeShader(this.bitmapShader, vignette, Mode.SRC_OVER)); }
Example #22
Source File: RoundedVignetteBitmapDisplayer.java From Android-Application-ZJB with Apache License 2.0 | 5 votes |
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); RadialGradient vignette = new RadialGradient( mRect.centerX(), mRect.centerY() * 1.0f / 0.7f, mRect.centerX() * 1.3f, new int[]{0, 0, 0x7f000000}, new float[]{0.0f, 0.7f, 1.0f}, Shader.TileMode.CLAMP); Matrix oval = new Matrix(); oval.setScale(1.0f, 0.7f); vignette.setLocalMatrix(oval); paint.setShader(new ComposeShader(bitmapShader, vignette, PorterDuff.Mode.SRC_OVER)); }
Example #23
Source File: RoundedVignetteBitmapDisplayer.java From letv with Apache License 2.0 | 5 votes |
protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); RadialGradient vignette = new RadialGradient(this.mRect.centerX(), (this.mRect.centerY() * 1.0f) / 0.7f, this.mRect.centerX() * 1.3f, new int[]{0, 0, 2130706432}, new float[]{0.0f, 0.7f, 1.0f}, TileMode.CLAMP); Matrix oval = new Matrix(); oval.setScale(1.0f, 0.7f); vignette.setLocalMatrix(oval); this.paint.setShader(new ComposeShader(this.bitmapShader, vignette, Mode.SRC_OVER)); }
Example #24
Source File: RadialGradientRippleView.java From AndroidDigIn with Apache License 2.0 | 5 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { float x = event.getX(); float y = event.getY(); //向中间0.5靠拢 RadialGradient radialGradient = new RadialGradient(x + mDisW, y + mDisH, mRadiusWidth, new int[]{Color.TRANSPARENT, Color.WHITE, Color.TRANSPARENT}, new float[]{0.15f, 0.45f, 0.75f},//一半一半 Shader.TileMode.REPEAT); ComposeShader composeShader = new ComposeShader(radialGradient, mBitmapShader, PorterDuff.Mode.SRC_IN); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setShader(composeShader); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(mRadiusWidth); RippleStuff rippleStuff = new RippleStuff(); rippleStuff.radius = mRadiusWidth; rippleStuff.paint = paint; rippleStuff.x = x; rippleStuff.y = y; mRippleStuffs.add(rippleStuff); createAnimatorAndStart(rippleStuff); } return true; }
Example #25
Source File: ViewfinderView.java From DoraemonKit with Apache License 2.0 | 5 votes |
private void drawLaserScanner(Canvas canvas, Rect frame) { paint.setColor(laserColor); //线性渐变 LinearGradient linearGradient = new LinearGradient( frame.left, scannerStart, frame.left, scannerStart + SCANNER_LINE_HEIGHT, shadeColor(laserColor), laserColor, Shader.TileMode.MIRROR); RadialGradient radialGradient = new RadialGradient( (float) (frame.left + frame.width() / 2), (float) (scannerStart + SCANNER_LINE_HEIGHT / 2), 360f, laserColor, shadeColor(laserColor), Shader.TileMode.MIRROR); SweepGradient sweepGradient = new SweepGradient( (float) (frame.left + frame.width() / 2), (float) (scannerStart + SCANNER_LINE_HEIGHT), shadeColor(laserColor), laserColor); ComposeShader composeShader = new ComposeShader(radialGradient, linearGradient, PorterDuff.Mode.ADD); paint.setShader(radialGradient); if (scannerStart <= scannerEnd) { //矩形 // canvas.drawRect(frame.left, scannerStart, frame.right, scannerStart + SCANNER_LINE_HEIGHT, paint); //椭圆 RectF rectF = new RectF(frame.left + 2 * SCANNER_LINE_HEIGHT, scannerStart, frame.right - 2 * SCANNER_LINE_HEIGHT, scannerStart + SCANNER_LINE_HEIGHT); canvas.drawOval(rectF, paint); scannerStart += SCANNER_LINE_MOVE_DISTANCE; } else { scannerStart = frame.top; } paint.setShader(null); }
Example #26
Source File: GameView.java From CanEffect with Apache License 2.0 | 4 votes |
public GameView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); /* 装载资源 */ mBitQQ = ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap(); /* 得到图片的宽度和高度 */ BitQQwidth = mBitQQ.getWidth(); BitQQheight = mBitQQ.getHeight(); /* 创建BitmapShader对象 */ mBitmapShader = new BitmapShader(mBitQQ,Shader.TileMode.REPEAT,Shader.TileMode.MIRROR); /* 创建LinearGradient并设置渐变的颜色数组 说明一下这几天参数 * 第一个 起始的x坐标 * 第二个 起始的y坐标 * 第三个 结束的x坐标 * 第四个 结束的y坐标 * 第五个 颜色数组 * 第六个 这个也是一个数组用来指定颜色数组的相对位置 如果为null 就沿坡度线均匀分布 * 第七个 渲染模式 * */ mLinearGradient = new LinearGradient(0,0,100,100, new int[]{Color.RED,Color.GREEN,Color.BLUE,Color.WHITE}, null,Shader.TileMode.REPEAT); /* 这里理解为混合渲染*/ mComposeShader = new ComposeShader(mBitmapShader,mLinearGradient,PorterDuff.Mode.DARKEN); /* 构建RadialGradient对象,设置半径的属性 */ //这里使用了BitmapShader和LinearGradient进行混合 //当然也可以使用其他的组合 //混合渲染的模式很多,可以根据自己需要来选择 mRadialGradient = new RadialGradient(50,200,50, new int[]{Color.GREEN,Color.RED,Color.BLUE,Color.WHITE}, null,Shader.TileMode.REPEAT); /* 构建SweepGradient对象 */ mSweepGradient = new SweepGradient(30,30,new int[]{Color.GREEN,Color.RED,Color.BLUE,Color.WHITE},null); mPaint = new Paint(); /* 开启线程 */ new Thread(this).start(); }
Example #27
Source File: ViewfinderView.java From QrCodeDemo4 with MIT License | 4 votes |
private void drawLaserScanner(Canvas canvas, Rect frame) { paint.setColor(laserColor); //扫描线闪烁效果 // paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); // scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; // int middle = frame.height() / 2 + frame.top; // canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); //线性渐变 LinearGradient linearGradient = new LinearGradient( frame.left, scannerStart, frame.left, scannerStart + SCANNER_LINE_HEIGHT, shadeColor(laserColor), laserColor, Shader.TileMode.MIRROR); RadialGradient radialGradient = new RadialGradient( (float)(frame.left + frame.width() / 2), (float)(scannerStart + SCANNER_LINE_HEIGHT / 2), 360f, laserColor, shadeColor(laserColor), Shader.TileMode.MIRROR); SweepGradient sweepGradient = new SweepGradient( (float)(frame.left + frame.width() / 2), (float)(scannerStart + SCANNER_LINE_HEIGHT), shadeColor(laserColor), laserColor); ComposeShader composeShader = new ComposeShader(radialGradient, linearGradient, PorterDuff.Mode.ADD); paint.setShader(radialGradient); if(scannerStart <= scannerEnd) { //矩形 // canvas.drawRect(frame.left, scannerStart, frame.right, scannerStart + SCANNER_LINE_HEIGHT, paint); //椭圆 RectF rectF = new RectF(frame.left + 2 * SCANNER_LINE_HEIGHT, scannerStart, frame.right - 2 * SCANNER_LINE_HEIGHT, scannerStart + SCANNER_LINE_HEIGHT); canvas.drawOval(rectF, paint); scannerStart += SCANNER_LINE_MOVE_DISTANCE; } else { scannerStart = frame.top; } paint.setShader(null); }
Example #28
Source File: ViewfinderView.java From vmqApk with MIT License | 4 votes |
private void drawLaserScanner(Canvas canvas, Rect frame) { paint.setColor(laserColor); //扫描线闪烁效果 // paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); // scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; // int middle = frame.height() / 2 + frame.top; // canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); //线性渐变 LinearGradient linearGradient = new LinearGradient( frame.left, scannerStart, frame.left, scannerStart + SCANNER_LINE_HEIGHT, shadeColor(laserColor), laserColor, Shader.TileMode.MIRROR); RadialGradient radialGradient = new RadialGradient( (float)(frame.left + frame.width() / 2), (float)(scannerStart + SCANNER_LINE_HEIGHT / 2), 360f, laserColor, shadeColor(laserColor), Shader.TileMode.MIRROR); SweepGradient sweepGradient = new SweepGradient( (float)(frame.left + frame.width() / 2), (float)(scannerStart + SCANNER_LINE_HEIGHT), shadeColor(laserColor), laserColor); ComposeShader composeShader = new ComposeShader(radialGradient, linearGradient, PorterDuff.Mode.ADD); paint.setShader(radialGradient); if(scannerStart <= scannerEnd) { //矩形 // canvas.drawRect(frame.left, scannerStart, frame.right, scannerStart + SCANNER_LINE_HEIGHT, paint); //椭圆 RectF rectF = new RectF(frame.left + 2 * SCANNER_LINE_HEIGHT, scannerStart, frame.right - 2 * SCANNER_LINE_HEIGHT, scannerStart + SCANNER_LINE_HEIGHT); canvas.drawOval(rectF, paint); scannerStart += SCANNER_LINE_MOVE_DISTANCE; } else { scannerStart = frame.top; } paint.setShader(null); }
Example #29
Source File: ViewfinderView.java From QrCodeLib with MIT License | 4 votes |
private void drawLaserScanner(Canvas canvas, Rect frame) { paint.setColor(laserColor); //扫描线闪烁效果 // paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); // scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; // int middle = frame.height() / 2 + frame.top; // canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); //线性渐变 LinearGradient linearGradient = new LinearGradient( frame.left, scannerStart, frame.left, scannerStart + SCANNER_LINE_HEIGHT, shadeColor(laserColor), laserColor, Shader.TileMode.MIRROR); RadialGradient radialGradient = new RadialGradient( (float) (frame.left + frame.width() / 2), (float) (scannerStart + SCANNER_LINE_HEIGHT / 2), 360f, laserColor, shadeColor(laserColor), Shader.TileMode.MIRROR); SweepGradient sweepGradient = new SweepGradient( (float) (frame.left + frame.width() / 2), (float) (scannerStart + SCANNER_LINE_HEIGHT), shadeColor(laserColor), laserColor); ComposeShader composeShader = new ComposeShader(radialGradient, linearGradient, PorterDuff.Mode.ADD); paint.setShader(radialGradient); if (scannerStart <= scannerEnd) { //矩形 // canvas.drawRect(frame.left, scannerStart, frame.right, scannerStart + SCANNER_LINE_HEIGHT, paint); //椭圆 RectF rectF = new RectF(frame.left + 2 * SCANNER_LINE_HEIGHT, scannerStart, frame.right - 2 * SCANNER_LINE_HEIGHT, scannerStart + SCANNER_LINE_HEIGHT); canvas.drawOval(rectF, paint); scannerStart += SCANNER_LINE_MOVE_DISTANCE; } else { scannerStart = frame.top; } paint.setShader(null); }