List of usage examples for android.graphics Canvas drawBitmap
public void drawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull Rect dst, @Nullable Paint paint)
From source file:com.crs4.roodin.moduletester.CustomView.java
@Override public void onDraw(Canvas canvas, Matrix matrix) { canvas.rotate(currentRotation, translateX, translateY); canvas.drawBitmap(blockImg, 0, 0, null); drawBarreds().draw(canvas);/*from w w w. j a va2 s . c o m*/ drawRadar(canvas); canvas.restore(); }
From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java
/** * Sets the downloaded attached image./*ww w. ja va 2 s . c o 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:Main.java
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap input, int pixels, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) { bitmapResult = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas canvas = new Canvas(bitmapResult); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0 + 5, 0 + 5, w - 5, h - 5); final RectF rectF = new RectF(rect); // make sure that our rounded corner is scaled appropriately final float roundPx = pixels * densityMultiplier; paint.setAntiAlias(true);//from w w w . ja v a2s .c o m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); // canvas.drawColor(Color.BLACK); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); // draw rectangles over the corners we want to be square if (squareTL) { canvas.drawRect(0, 0, w / 2, h / 2, paint); } if (squareTR) { canvas.drawRect(w / 2, 0, w, h / 2, paint); } if (squareBL) { canvas.drawRect(0, h / 2, w / 2, h, paint); } if (squareBR) { canvas.drawRect(w / 2, h / 2, w, h, paint); } paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // paint.setXfermode(new AvoidXfermode(Color.WHITE, 255, // AvoidXfermode.Mode.TARGET)); canvas.drawBitmap(input, 0, 0, paint); return bitmapResult; }
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 www .j av a 2s . 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.channelsoft.common.bitmapUtil.ImageWorker.java
/** * ?// w w w .j av a 2 s .c o m * @param bmpOriginal * @return */ public static Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight(); width = bmpOriginal.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; }
From source file:com.nextgis.maplibui.formcontrol.Sign.java
@Override protected void onDraw(Canvas canvas) { if (mNotInitialized && mPreviousSignBitmap != null) canvas.drawBitmap(mPreviousSignBitmap, 0, 0, null); int posX = canvas.getWidth() - mClearImageSize - mClearBuff; mCleanImage.setBounds(posX, mClearBuff, posX + mClearImageSize, mClearImageSize + mClearBuff); mCleanImage.draw(canvas);/*from w w w . j a va2s .c om*/ if (!mNotInitialized) for (Path path : mPaths) canvas.drawPath(path, mPaint); }
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 av 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:com.fastaccess.tfl.ui.widget.drag.DragView.java
@Override protected void onDraw(Canvas canvas) { float scale = mAnimationScale; if (scale < 0.999f) { float width = mBitmap.getWidth(); float offset = (width - (width * scale)) / 2; canvas.translate(offset, offset); canvas.scale(scale, scale);//from ww w . j a v a 2 s.com } canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint); }
From source file:ch.jeda.platform.android.CanvasFragment.java
void setBitmap(final Bitmap bitmap) { if (this.surfaceAvailable) { final Canvas canvas = this.surfaceHolder.lockCanvas(); if (canvas != null) { canvas.drawBitmap(bitmap, 0f, 0f, null); this.surfaceHolder.unlockCanvasAndPost(canvas); }/*w w w. j a v a 2s . c om*/ } }
From source file:com.crystal.CrystalBeanWallpapers.Wallpaper.java
private Bitmap getColoredBitmap(Bitmap src, int color) { int width = src.getWidth(); int height = src.getHeight(); Bitmap dest = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(dest); Paint paint = new Paint(); paint.setColorFilter(new PorterDuffColorFilter(color, Mode.OVERLAY)); canvas.drawBitmap(src, 0, 0, paint); return dest;// w ww. j ava2 s .c om }