List of usage examples for android.graphics Canvas drawARGB
public void drawARGB(int a, int r, int g, int b)
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);// ww w .j a va 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(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./*w w w . j ava2 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 ww .j a va 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;/*from w w w . 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.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 ww w . j a va 2s . 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); return output; }
From source file:com.github.kubatatami.RoundedView.java
@Override protected void onDraw(Canvas canvas) { paint.setAntiAlias(true);// w w w . j ava 2 s .c o m paint.setFilterBitmap(true); paint.setDither(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, paint); if (text != null && !checked) { drawText(canvas); } if (checked && text == null) { drawChecked(canvas); } }
From source file:ggikko.me.steppertest.stepper.RoundedView.java
@Override protected void onDraw(Canvas canvas) { //if (getBackgroundColor(this) != 0) color = getBackgroundColor(this); paint.setAntiAlias(true);/*from ww w.j a v a2 s . c om*/ paint.setFilterBitmap(true); paint.setDither(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, paint); if (text != null && !checked) drawText(canvas); if (checked && text == null) drawChecked(canvas); }
From source file:com.appbase.androidquery.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 ww w.j a v a 2s . 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); return output; }
From source file:id.satusatudua.sigap.ui.fragment.GuardingLocationFragment.java
private Bitmap getCircleBitmap(Bitmap bitmap) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.RED; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true);//from w ww.ja v a 2 s . c o m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; }
From source file:com.bamobile.fdtks.util.Tools.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output;/*from ww w .j a v a 2 s . c om*/ if (bitmap.getWidth() > bitmap.getHeight()) { output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Config.ARGB_8888); } else { output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), 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()); float r = 0; if (bitmap.getWidth() > bitmap.getHeight()) { r = bitmap.getHeight() / 2; } else { r = bitmap.getWidth() / 2; } paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(r, r, r, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }