List of usage examples for android.graphics RectF centerX
public final float centerX()
From source file:Main.java
public static boolean setImageToScreenMatrix(Matrix dst, RectF image, RectF screen, int rotation) { RectF rotatedImage = new RectF(); dst.setRotate(rotation, image.centerX(), image.centerY()); if (!dst.mapRect(rotatedImage, image)) { return false; // fails for rotations that are not multiples of 90 // degrees }//from w w w .j a v a 2 s.c o m boolean rToR = dst.setRectToRect(rotatedImage, screen, Matrix.ScaleToFit.CENTER); boolean rot = dst.preRotate(rotation, image.centerX(), image.centerY()); return rToR && rot; }
From source file:Main.java
public static void drawWallpaperSelectionFrame(Canvas canvas, RectF cropBounds, float spotX, float spotY, Paint p, Paint shadowPaint) { float sx = cropBounds.width() * spotX; float sy = cropBounds.height() * spotY; float cx = cropBounds.centerX(); float cy = cropBounds.centerY(); RectF r1 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2); float temp = sx; sx = sy;/* w ww .j a va2s. c om*/ sy = temp; RectF r2 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2); canvas.save(); canvas.clipRect(cropBounds); canvas.clipRect(r1, Region.Op.DIFFERENCE); canvas.clipRect(r2, Region.Op.DIFFERENCE); canvas.drawPaint(shadowPaint); canvas.restore(); Path path = new Path(); path.moveTo(r1.left, r1.top); path.lineTo(r1.right, r1.top); path.moveTo(r1.left, r1.top); path.lineTo(r1.left, r1.bottom); path.moveTo(r1.left, r1.bottom); path.lineTo(r1.right, r1.bottom); path.moveTo(r1.right, r1.top); path.lineTo(r1.right, r1.bottom); path.moveTo(r2.left, r2.top); path.lineTo(r2.right, r2.top); path.moveTo(r2.right, r2.top); path.lineTo(r2.right, r2.bottom); path.moveTo(r2.left, r2.bottom); path.lineTo(r2.right, r2.bottom); path.moveTo(r2.left, r2.top); path.lineTo(r2.left, r2.bottom); canvas.drawPath(path, p); }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap3(Drawable imageDrawable, int radius) { Bitmap d = ((BitmapDrawable) imageDrawable).getBitmap(); BitmapShader shader = new BitmapShader(d, TileMode.CLAMP, TileMode.CLAMP); int size = Math.min(d.getWidth(), d.getHeight()); Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); // float cornerRadius = radius; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setShader(shader);// www. ja v a 2 s. c o m paint.setAntiAlias(true); paint.setColor(Color.RED); canvas.drawCircle(outerRect.centerX(), outerRect.centerY(), d.getWidth() / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); Canvas canvas1 = new Canvas(output); RectF outerRect1 = new RectF(0, 0, size, size); Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG); paint1.setShader(shader); paint1.setAntiAlias(true); paint1.setColor(Color.RED); canvas1.drawCircle(outerRect1.centerX(), outerRect1.centerY(), d.getWidth() / 2, paint); paint1.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); return output; }
From source file:Main.java
public static Bitmap cropImage(RectF rect, Bitmap bitmap) { float width = rect.width() * 2; if (width > bitmap.getWidth()) { width = bitmap.getWidth();/* w w w . jav a 2 s. c o m*/ } float hight = rect.height() * 2; if (hight > bitmap.getHeight()) { hight = bitmap.getHeight(); } float l = rect.centerX() - (width / 2); if (l < 0) { l = 0; } float t = rect.centerY() - (hight / 2); if (t < 0) { t = 0; } if (l + width > bitmap.getWidth()) { width = bitmap.getWidth() - l; } if (t + hight > bitmap.getHeight()) { hight = bitmap.getHeight() - t; } return Bitmap.createBitmap(bitmap, (int) l, (int) t, (int) width, (int) hight); }
From source file:com.jrummyapps.android.widget.AnimatedSvgView.java
/** * If you set the SVG data paths more than once using {@link #setGlyphStrings(String...)} you should call this method * before playing the animation.//from www. jav a2 s .co m */ @SuppressWarnings("SuspiciousNameCombination") public void rebuildGlyphData() { float X = mWidth / mViewport.x; float Y = mHeight / mViewport.y; Matrix scaleMatrix = new Matrix(); RectF outerRect = new RectF(X, X, Y, Y); scaleMatrix.setScale(X, Y, outerRect.centerX(), outerRect.centerY()); mGlyphData = new GlyphData[mGlyphStrings.length]; for (int i = 0; i < mGlyphStrings.length; i++) { mGlyphData[i] = new GlyphData(); try { mGlyphData[i].path = ExposedPathParser.createPathFromPathData(mGlyphStrings[i]); mGlyphData[i].path.transform(scaleMatrix); } catch (Exception e) { mGlyphData[i].path = new Path(); Log.e(TAG, "Couldn't parse path", e); } PathMeasure pm = new PathMeasure(mGlyphData[i].path, true); while (true) { mGlyphData[i].length = Math.max(mGlyphData[i].length, pm.getLength()); if (!pm.nextContour()) { break; } } mGlyphData[i].paint = new Paint(); mGlyphData[i].paint.setStyle(Paint.Style.STROKE); mGlyphData[i].paint.setAntiAlias(true); mGlyphData[i].paint.setColor(Color.WHITE); mGlyphData[i].paint.setStrokeWidth( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics())); } }
From source file:de.vanita5.twittnuker.view.ShapedImageView.java
/** * Given the source bitmap and a canvas, draws the bitmap through a circular * mask. Only draws a circle with diameter equal to the destination width. * * @param bitmap The source bitmap to draw. * @param canvas The canvas to draw it on. * @param source The source bound of the bitmap. * @param dest The destination bound on the canvas. *///from www .ja va 2s .co m public void drawBitmapWithCircleOnCanvas(Bitmap bitmap, Canvas canvas, RectF source, @NonNull RectF dest) { if (bitmap == null) { if (getStyle() == SHAPE_CIRCLE) { canvas.drawCircle(dest.centerX(), dest.centerY(), Math.min(dest.width(), dest.height()) / 2f, mSolidColorPaint); } else { final float cornerRadius = getCalculatedCornerRadius(); canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mSolidColorPaint); } return; } // Draw bitmap through shader first. final BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mMatrix.reset(); switch (getScaleType()) { case CENTER_CROP: { final float srcRatio = source.width() / source.height(); final float dstRatio = dest.width() / dest.height(); if (srcRatio > dstRatio) { // Source is wider than destination, fit height mTempDestination.top = dest.top; mTempDestination.bottom = dest.bottom; final float dstWidth = dest.height() * srcRatio; mTempDestination.left = dest.centerX() - dstWidth / 2; mTempDestination.right = dest.centerX() + dstWidth / 2; } else if (srcRatio < dstRatio) { mTempDestination.left = dest.left; mTempDestination.right = dest.right; final float dstHeight = dest.width() / srcRatio; mTempDestination.top = dest.centerY() - dstHeight / 2; mTempDestination.bottom = dest.centerY() + dstHeight / 2; } else { mTempDestination.set(dest); } break; } default: { mTempDestination.set(dest); break; } } // Fit bitmap to bounds. mMatrix.setRectToRect(source, mTempDestination, ScaleToFit.CENTER); shader.setLocalMatrix(mMatrix); mBitmapPaint.setShader(shader); if (getStyle() == SHAPE_CIRCLE) { canvas.drawCircle(dest.centerX(), dest.centerY(), Math.min(dest.width(), dest.height()) / 2f, mBitmapPaint); } else { final float cornerRadius = getCalculatedCornerRadius(); canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mBitmapPaint); } }
From source file:com.digitalvotingpass.camera.CameraFragment.java
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` *///from w ww.j a v a2 s. co m public void configureTransform(int viewWidth, int viewHeight) { Activity activity = getActivity(); if (null == mTextureView || null == mPreviewSize || null == activity) { return; } int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(), (float) viewWidth / mPreviewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } mTextureView.setTransform(matrix); overlay.setRect(CameraFragmentUtil.getScanRect(scanSegment)); }
From source file:org.getlantern.firetweet.view.ShapedImageView.java
/** * Given the source bitmap and a canvas, draws the bitmap through a circular * mask. Only draws a circle with diameter equal to the destination width. * * @param bitmap The source bitmap to draw. * @param canvas The canvas to draw it on. * @param source The source bound of the bitmap. * @param dest The destination bound on the canvas. */// www . ja va2 s. c o m public void drawBitmapWithCircleOnCanvas(Bitmap bitmap, Canvas canvas, RectF source, @NonNull RectF dest) { if (bitmap == null) { if (getStyle() == SHAPE_CIRCLE) { canvas.drawCircle(dest.centerX(), dest.centerY(), Math.min(dest.width(), dest.height()) / 2f, mSolidColorPaint); } else { final float cornerRadius = getCalculatedCornerRadius(); canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mSolidColorPaint); } return; } // Draw bitmap through shader first. final BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mMatrix.reset(); switch (getScaleType()) { case CENTER_CROP: { final float srcRatio = source.width() / source.height(); final float dstRatio = dest.width() / dest.height(); if (srcRatio > dstRatio) { // Source is wider than destination, fit height mTempDestination.top = dest.top; mTempDestination.bottom = dest.bottom; final float dstWidth = dest.height() * srcRatio; mTempDestination.left = dest.centerX() - dstWidth / 2; mTempDestination.right = dest.centerX() + dstWidth / 2; } else if (srcRatio < dstRatio) { mTempDestination.left = dest.left; mTempDestination.right = dest.right; final float dstHeight = dest.width() / srcRatio; mTempDestination.top = dest.centerY() - dstHeight / 2; mTempDestination.bottom = dest.centerY() + dstHeight / 2; } else { mTempDestination.set(dest); } break; } default: { mTempDestination.set(dest); break; } } // Fit bitmap to bounds. mMatrix.setRectToRect(source, mTempDestination, ScaleToFit.CENTER); shader.setLocalMatrix(mMatrix); mBitmapPaint.setShader(shader); if (mBorderEnabled) { final float inset = mBorderPaint.getStrokeWidth() / 2; if (getStyle() == SHAPE_CIRCLE) { final float circleRadius = Math.min(dest.width(), dest.height()) / 2f - inset / 2; canvas.drawCircle(dest.centerX(), dest.centerY(), circleRadius, mBitmapPaint); } else { final float cornerRadius = getCalculatedCornerRadius(); dest.inset(inset, inset); canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mBitmapPaint); dest.inset(-inset, -inset); } } else { if (getStyle() == SHAPE_CIRCLE) { final float circleRadius = Math.min(dest.width(), dest.height()) / 2f; canvas.drawCircle(dest.centerX(), dest.centerY(), circleRadius, mBitmapPaint); } else { final float cornerRadius = getCalculatedCornerRadius(); canvas.drawRoundRect(dest, cornerRadius, cornerRadius, mBitmapPaint); } } }
From source file:android.support.design.widget.CircularBorderDrawable.java
@Override public void draw(Canvas canvas) { if (mInvalidateShader) { mPaint.setShader(createGradientShader()); mInvalidateShader = false;/*from w w w.jav a 2s.co m*/ } final float halfBorderWidth = mPaint.getStrokeWidth() / 2f; final RectF rectF = mRectF; // We need to inset the oval bounds by half the border width. This is because stroke draws // the center of the border on the dimension. Whereas we want the stroke on the inside. copyBounds(mRect); rectF.set(mRect); rectF.left += halfBorderWidth; rectF.top += halfBorderWidth; rectF.right -= halfBorderWidth; rectF.bottom -= halfBorderWidth; canvas.save(); canvas.rotate(mRotation, rectF.centerX(), rectF.centerY()); // Draw the oval canvas.drawOval(rectF, mPaint); canvas.restore(); }
From source file:com.raulh82vlc.face_detection_sample.camera2.presentation.FDCamera2Presenter.java
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` *//* w ww .ja va 2 s .c om*/ private void configureTransform(int viewWidth, int viewHeight) { if (isViewAvailable()) { if (null == activityView.getTextureView()) { return; } int rotation = activityView.getWindowManager().getDefaultDisplay().getRotation(); Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth()); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); float scale = Math.max((float) viewHeight / previewSize.getHeight(), (float) viewWidth / previewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } activityView.getTextureView().setTransform(matrix); } }