List of usage examples for android.graphics Canvas drawRoundRect
public void drawRoundRect(@NonNull RectF rect, float rx, float ry, @NonNull Paint paint)
From source file:com.almalence.googsharing.Thumbnail.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int size, int pixels) { final int side = Math.min(bitmap.getWidth(), bitmap.getHeight()); final Bitmap bitmapCropped = Bitmap.createBitmap(bitmap, (bitmap.getWidth() - side) / 2, (bitmap.getHeight() - side) / 2, side, side); final Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xffffffff; final Paint paint = new Paint(); final Rect rectSrc = new Rect(0, 0, bitmapCropped.getWidth(), bitmapCropped.getHeight()); final Rect rect = new Rect(6, 6, output.getWidth() - 6, output.getHeight() - 6); final RectF rectF = new RectF(rect); final RectF rectFBorder = new RectF(0, 0, output.getWidth(), output.getHeight()); final float roundPx = pixels; paint.setAntiAlias(true);/*from w w w . j a v a 2 s . c om*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmapCropped, rectSrc, rect, paint); paint.setXfermode(new PorterDuffXfermode(Mode.DST_ATOP)); canvas.drawRoundRect(rectFBorder, roundPx, roundPx, paint); return output; }
From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java
/** * Sets the downloaded attached image.//from w w w. ja v a 2 s .co m * * @param fileName picture file path */ public static Bitmap publishPicture(String fileName) { Bitmap bitmap = null; try { if (!TextUtils.isEmpty(fileName)) { try { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(fileName, opts); //Find the correct scale value. It should be the power of 2. int width = opts.outWidth, height = opts.outHeight; int scale = 1; while (true) { if (width / 2 <= 150 || height / 2 <= 150) { break; } width /= 2; height /= 2; scale *= 2; } BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inSampleSize = scale; bitmap = BitmapFactory.decodeFile(fileName, opt); int size = 0; if (bitmap.getHeight() > bitmap.getWidth()) { size = bitmap.getWidth(); } else { size = bitmap.getHeight(); } Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, size, size); final RectF rectF = new RectF(rect); final float roundPx = 0; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; } catch (Exception e) { Log.w("", ""); } } } catch (Exception ex) { } return null; }
From source file:com.c4mprod.utils.ImageManager.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = 20; paint.setAntiAlias(true);/*from w w w .j a v a 2 s . c o m*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); if (output != bitmap) { bitmap.recycle(); } return output; }
From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java
public static Bitmap resizeAndRoundCorners(Bitmap bitmap, int maxSize) { boolean isLandscape = bitmap.getWidth() > bitmap.getHeight(); int newWidth, newHeight; if (isLandscape) { newWidth = maxSize;// w ww .j a v a 2 s.co m newHeight = Math.round(((float) newWidth / bitmap.getWidth()) * bitmap.getHeight()); } else { newHeight = maxSize; newWidth = Math.round(((float) newHeight / bitmap.getHeight()) * bitmap.getWidth()); } Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false); if (resizedBitmap != bitmap) bitmap.recycle(); Bitmap roundedProfile = Bitmap.createBitmap(resizedBitmap.getWidth(), resizedBitmap.getHeight(), Config.ARGB_8888); Canvas roundedCanvas = new Canvas(roundedProfile); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, roundedProfile.getWidth(), roundedProfile.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = 7.0f; paint.setAntiAlias(true); roundedCanvas.drawARGB(0, 0, 0, 0); paint.setColor(color); roundedCanvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); roundedCanvas.drawBitmap(resizedBitmap, rect, rect, paint); return roundedProfile; }
From source file:com.busdrone.android.ui.VehicleMarkerRenderer.java
private Bitmap render(int color, String text) { TextPaint textPaint = new TextPaint(); textPaint.setColor(Color.WHITE); textPaint.setStyle(Paint.Style.FILL); textPaint.setAntiAlias(true);/* w ww .j av a2 s . c om*/ textPaint.setTextSize(mTextSize); Rect textBounds = new Rect(); textPaint.getTextBounds(text, 0, text.length(), textBounds); int width = mPadding + textBounds.width() + mPadding; int height = mPadding + textBounds.height() + mPadding; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(color); canvas.drawRoundRect(new RectF(0, 0, width, height), mCornerRadius, mCornerRadius, paint); canvas.drawText(text, (width / 2f) - (textBounds.width() / 2f), (height / 2f) + (textBounds.height() / 2f), textPaint); return bitmap; }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; paint.setAntiAlias(true);//from www . j a v a2s . co m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:com.liferay.mobile.screens.viewsets.defaultviews.userportrait.UserPortraitView.java
protected Bitmap transformBitmap(Bitmap bitmap) { float borderRadius = getBorderRadius(); float borderWidth = getBorderWidth(); RectF rect = getRectF(bitmap, borderWidth); Bitmap finalBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(finalBitmap); canvas.drawRoundRect(rect, borderRadius, borderRadius, getPaint(bitmap)); canvas.drawRoundRect(rect, borderRadius, borderRadius, getBorderPaint(borderWidth, getDefaultBorderColor())); return finalBitmap; }
From source file:com.manning.androidhacks.hack007.view.Rectangle.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mDrawRect.set(mCoordX, mCoordY, mCoordX + mRealSize, mCoordY + mRealSize); canvas.drawRoundRect(mDrawRect, 0, 0, mInnerPaint); }
From source file:me.uucky.colorpicker.internal.ColorView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mRect.left = 0;//from w w w . ja va2 s.c om mRect.top = 0; mRect.right = getWidth(); mRect.bottom = getHeight(); canvas.drawRoundRect(mRect, mRadius, mRadius, mAlphaPatternPaint); canvas.drawRoundRect(mRect, mRadius, mRadius, mColorPaint); }
From source file:com.king.android.common.widget.badge.BGADragBadgeView.java
private void drawTextBadge(Canvas canvas) { // ? mBadgePaint.setColor(mBadgeViewHelper.getBadgeBgColor()); // /*from ww w . j a v a 2 s.c o m*/ canvas.drawRoundRect( new RectF(mStartX, mStartY, mStartX + mBadgeViewHelper.getBadgeRectF().width(), mStartY + mBadgeViewHelper.getBadgeRectF().height()), mBadgeViewHelper.getBadgeRectF().height() / 2, mBadgeViewHelper.getBadgeRectF().height() / 2, mBadgePaint); // mBadgePaint.setColor(mBadgeViewHelper.getBadgeTextColor()); float x = mStartX + mBadgeViewHelper.getBadgeRectF().width() / 2; // ?y??? float y = mStartY + mBadgeViewHelper.getBadgeRectF().height() - mBadgeViewHelper.getBadgePadding(); // String badgeText = mBadgeViewHelper.getBadgeText() == null ? "" : mBadgeViewHelper.getBadgeText(); canvas.drawText(badgeText, x, y, mBadgePaint); }