Java Code Examples for android.graphics.Canvas#clipOutPath()
The following examples show how to use
android.graphics.Canvas#clipOutPath() .
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: SimulationPageAnim.java From a with GNU General Public License v3.0 | 6 votes |
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap, Path path) { mPath0.reset(); mPath0.moveTo(mBezierStart1.x, mBezierStart1.y); mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x, mBezierEnd1.y); mPath0.lineTo(mTouchX, mTouchY); mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y); mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y); mPath0.lineTo(mCornerX, mCornerY); mPath0.close(); canvas.save(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { canvas.clipOutPath(path); } else { canvas.clipPath(path, Region.Op.XOR); } canvas.drawBitmap(bitmap, 0, 0, null); try { canvas.restore(); } catch (Exception e) { e.printStackTrace(); } }
Example 2
Source File: SimulationPageAnim.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap) { mPath0.reset(); mPath0.moveTo(mBezierStart1.x, mBezierStart1.y); mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x, mBezierEnd1.y); mPath0.lineTo(mTouchX, mTouchY); mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y); mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y); mPath0.lineTo(mCornerX, mCornerY); mPath0.close(); canvas.save(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { canvas.clipOutPath(mPath0); } else { canvas.clipPath(mPath0, Region.Op.XOR); } canvas.drawBitmap(bitmap, 0, 0, null); try { canvas.restore(); } catch (Exception e) { e.printStackTrace(); } }
Example 3
Source File: SimulationPageAnim.java From HaoReader with GNU General Public License v3.0 | 6 votes |
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap, Path path) { mPath0.reset(); mPath0.moveTo(mBezierStart1.x, mBezierStart1.y); mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x, mBezierEnd1.y); mPath0.lineTo(mTouchX, mTouchY); mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y); mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y); mPath0.lineTo(mCornerX, mCornerY); mPath0.close(); canvas.save(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { canvas.clipOutPath(path); } else { canvas.clipPath(path, Region.Op.XOR); } canvas.drawBitmap(bitmap, 0, 0, null); try { canvas.restore(); } catch (Exception e) { e.printStackTrace(); } }
Example 4
Source File: CropImageView.java From edx-app-android with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Draw background with transparent circular hole final float radius = Math.min((float) canvas.getWidth(), canvas.getHeight()) / 2 - cropCirclePadding; mRectF.set((float) canvas.getWidth() / 2 - radius, (float) canvas.getHeight() / 2 - radius, (float) canvas.getWidth() / 2 + radius, (float) canvas.getHeight() / 2 + radius); circleSelectionPath.reset(); circleSelectionPath.addOval(mRectF, Path.Direction.CW); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { canvas.clipOutPath(circleSelectionPath); } else { canvas.clipPath(circleSelectionPath, Region.Op.XOR); } canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), backgroundPaint); // Canvas did not save and called restore due to which app crashes, so we have to save first then call restore canvas.save(); canvas.restore(); // Draw circle border canvas.drawCircle((float) canvas.getWidth() / 2, (float) canvas.getHeight() / 2, radius, borderPaint); }
Example 5
Source File: Utils.java From ClipPathLayout with Apache License 2.0 | 5 votes |
public static void clipOutPath(Canvas canvas, Path path) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { canvas.clipOutPath(path); } else { canvas.clipPath(path, Region.Op.DIFFERENCE); } }
Example 6
Source File: ClipView.java From PlusDemo with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.save(); canvas.clipOutPath(path); canvas.drawBitmap(bitmap, 0, 0, paint); canvas.restore(); }
Example 7
Source File: CropOverlayView.java From Lassi-Android with MIT License | 4 votes |
/** * Draw shadow background over the image not including the crop area. */ private void drawBackground(Canvas canvas) { RectF rect = mCropWindowHandler.getRect(); float left = Math.max(BitmapUtils.getRectLeft(mBoundsPoints), 0); float top = Math.max(BitmapUtils.getRectTop(mBoundsPoints), 0); float right = Math.min(BitmapUtils.getRectRight(mBoundsPoints), getWidth()); float bottom = Math.min(BitmapUtils.getRectBottom(mBoundsPoints), getHeight()); if (mCropShape == CropImageView.CropShape.RECTANGLE) { if (!isNonStraightAngleRotated() || Build.VERSION.SDK_INT <= 17) { canvas.drawRect(left, top, right, rect.top, mBackgroundPaint); canvas.drawRect(left, rect.bottom, right, bottom, mBackgroundPaint); canvas.drawRect(left, rect.top, rect.left, rect.bottom, mBackgroundPaint); canvas.drawRect(rect.right, rect.top, right, rect.bottom, mBackgroundPaint); } else { mPath.reset(); mPath.moveTo(mBoundsPoints[0], mBoundsPoints[1]); mPath.lineTo(mBoundsPoints[2], mBoundsPoints[3]); mPath.lineTo(mBoundsPoints[4], mBoundsPoints[5]); mPath.lineTo(mBoundsPoints[6], mBoundsPoints[7]); mPath.close(); canvas.save(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { canvas.clipOutPath(mPath); } else { canvas.clipPath(mPath, Region.Op.INTERSECT); } canvas.clipRect(rect, Region.Op.XOR); canvas.drawRect(left, top, right, bottom, mBackgroundPaint); canvas.restore(); } } else { mPath.reset(); if (Build.VERSION.SDK_INT <= 17 && mCropShape == CropImageView.CropShape.OVAL) { mDrawRect.set(rect.left + 2, rect.top + 2, rect.right - 2, rect.bottom - 2); } else { mDrawRect.set(rect.left, rect.top, rect.right, rect.bottom); } mPath.addOval(mDrawRect, Path.Direction.CW); canvas.save(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { canvas.clipOutPath(mPath); } else { canvas.clipPath(mPath, Region.Op.XOR); } canvas.drawRect(left, top, right, bottom, mBackgroundPaint); canvas.restore(); } }
Example 8
Source File: CropOverlayView.java From Android-Image-Cropper with Apache License 2.0 | 4 votes |
/** Draw shadow background over the image not including the crop area. */ private void drawBackground(Canvas canvas) { RectF rect = mCropWindowHandler.getRect(); float left = Math.max(BitmapUtils.getRectLeft(mBoundsPoints), 0); float top = Math.max(BitmapUtils.getRectTop(mBoundsPoints), 0); float right = Math.min(BitmapUtils.getRectRight(mBoundsPoints), getWidth()); float bottom = Math.min(BitmapUtils.getRectBottom(mBoundsPoints), getHeight()); if (mCropShape == CropImageView.CropShape.RECTANGLE) { if (!isNonStraightAngleRotated() || Build.VERSION.SDK_INT <= 17) { canvas.drawRect(left, top, right, rect.top, mBackgroundPaint); canvas.drawRect(left, rect.bottom, right, bottom, mBackgroundPaint); canvas.drawRect(left, rect.top, rect.left, rect.bottom, mBackgroundPaint); canvas.drawRect(rect.right, rect.top, right, rect.bottom, mBackgroundPaint); } else { mPath.reset(); mPath.moveTo(mBoundsPoints[0], mBoundsPoints[1]); mPath.lineTo(mBoundsPoints[2], mBoundsPoints[3]); mPath.lineTo(mBoundsPoints[4], mBoundsPoints[5]); mPath.lineTo(mBoundsPoints[6], mBoundsPoints[7]); mPath.close(); canvas.save(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { canvas.clipOutPath(mPath); } else { canvas.clipPath(mPath, Region.Op.INTERSECT); } canvas.clipRect(rect, Region.Op.XOR); canvas.drawRect(left, top, right, bottom, mBackgroundPaint); canvas.restore(); } } else { mPath.reset(); if (Build.VERSION.SDK_INT <= 17 && mCropShape == CropImageView.CropShape.OVAL) { mDrawRect.set(rect.left + 2, rect.top + 2, rect.right - 2, rect.bottom - 2); } else { mDrawRect.set(rect.left, rect.top, rect.right, rect.bottom); } mPath.addOval(mDrawRect, Path.Direction.CW); canvas.save(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { canvas.clipOutPath(mPath); } else { canvas.clipPath(mPath, Region.Op.XOR); } canvas.drawRect(left, top, right, bottom, mBackgroundPaint); canvas.restore(); } }