List of usage examples for android.graphics Bitmap getWidth
public final int getWidth()
From source file:Main.java
private static void drawTouchIconToCanvas(Bitmap touchIcon, Canvas canvas, Rect iconBounds) { Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight()); // Paint used for scaling the bitmap and drawing the rounded rect. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setFilterBitmap(true);/*w ww . ja v a 2s . c o m*/ canvas.drawBitmap(touchIcon, src, iconBounds, paint); // Construct a path from a round rect. This will allow drawing with // an inverse fill so we can punch a hole using the round rect. Path path = new Path(); path.setFillType(Path.FillType.INVERSE_WINDING); RectF rect = new RectF(iconBounds); rect.inset(1, 1); path.addRoundRect(rect, 8f, 8f, Path.Direction.CW); // Reuse the paint and clear the outside of the rectangle. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawPath(path, paint); }
From source file:Main.java
public static Bitmap scaleBitmap(Bitmap bitmap, int reW, int reH) { if (bitmap == null) { return null; }/* w ww.j a v a2 s . c o m*/ int bmpW = bitmap.getWidth(); int bmpH = bitmap.getHeight(); float wScale = reW * 1.0f / bmpW; float hScale = reH * 1.0f / bmpH; float scale = Math.max(wScale, hScale); Matrix matrix = new Matrix(); matrix.setScale(scale, scale); return Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, matrix, true); }
From source file:Main.java
public static Bitmap getCircleCroppedBitmap(Bitmap bitmap) { if (bitmap == null) return null; final int srcSize = Math.min(bitmap.getWidth(), bitmap.getHeight()); return getScaledCircleCroppedBitmap(bitmap, srcSize); }
From source file:Main.java
public static Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) { int sourceWidth = source.getWidth(); int sourceHeight = source.getHeight(); // Compute the scaling factors to fit the new height and width, respectively. // To cover the final image, the final scaling will be the bigger // of these two. float xScale = (float) newWidth / sourceWidth; float yScale = (float) newHeight / sourceHeight; float scale = Math.max(xScale, yScale); // Now get the size of the source bitmap when scaled float scaledWidth = scale * sourceWidth; float scaledHeight = scale * sourceHeight; // Let's find out the upper left coordinates if the scaled bitmap // should be centered in the new size give by the parameters float left = (newWidth - scaledWidth) / 2; float top = (newHeight - scaledHeight) / 2; // The target rectangle for the new, scaled version of the source bitmap will now // be//from w ww . j av a 2 s .c o m RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight); // Finally, we create a new bitmap of the specified size and draw our new, // scaled bitmap onto it. Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, CONFIG); Canvas canvas = new Canvas(dest); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawBitmap(source, null, targetRect, paint); return dest; }
From source file:Main.java
public static Bitmap LoadFliped(Bitmap src) { Matrix matrix = new Matrix(); matrix.preScale(-1.0f, 1.0f);//from w w w .j av a2 s . c o m return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); }
From source file:Main.java
public static Point getImageMaxDimension(Context context, int[] imgRes) { final Point point = new Point(); for (int i = 0, length = imgRes.length; i < length; i++) { Bitmap tmp = BitmapFactory.decodeResource(context.getResources(), imgRes[i]); int width = tmp.getWidth(); int height = tmp.getHeight(); tmp.recycle();// w w w . ja va 2 s . co m tmp = null; if (point.x < width) { point.x = width; } if (point.y < height) { point.y = height; } } return point; }
From source file:Main.java
/** * Creates a <tt>Bitmap</tt> with rounded corners. * @param bitmap the bitmap that will have it's corners rounded. * @param factor factor used to calculate corners radius based on width * and height of the image. * @return a <tt>Bitmap</tt> with rounded corners created from given * <tt>bitmap</tt>./* w ww. j a va 2 s . c o m*/ */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float factor) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.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); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); float rX = ((float) bitmap.getWidth()) * factor; float rY = ((float) bitmap.getHeight()) * factor; //float r = (rX+rY)/2; canvas.drawRoundRect(rectF, rX, rY, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap transferMode(Bitmap src, Bitmap mask, Xfermode xfermode) { final int width = mask.getWidth(); final int height = mask.getHeight(); final Bitmap dst = Bitmap.createBitmap(width, height, Config.ARGB_8888); final Canvas canvas = new Canvas(dst); final Paint paint = new Paint(); paint.setAntiAlias(true);//from ww w . j a v a 2s . co m final int srcWidth = src.getWidth(); final int srcHeight = src.getHeight(); canvas.save(); // Scale down the image first if required. if ((width < srcWidth) || (height < srcHeight)) { float radioX = (float) width / srcWidth; float radioY = (float) height / srcHeight; float radio = 1f; float dx = 0f; float dy = 0f; if (radioX > radioY) { radio = radioX; dy = (height / radioX - srcHeight) / 2.0f; } else { radio = radioY; dx = (width / radioX - srcWidth) / 2.0f; } canvas.scale(radio, radio); canvas.translate(dx, dy); } canvas.drawBitmap(src, 0, 0, paint); canvas.restore(); if (xfermode != null) { paint.setXfermode(xfermode); canvas.drawBitmap(mask, 0, 0, paint); } return dst; }
From source file:Main.java
public static void blur(Context context, Bitmap bkg, View view, int width, int height) { float radius = 20; Log.i("hulixia", bkg.getWidth() + "w,h" + bkg.getDensity()); Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft(), -view.getTop()); canvas.drawBitmap(bkg, 0, 0, null);// ww w . j a v a2s. c om RenderScript rs = RenderScript.create(context); Allocation overlayAlloc = Allocation.createFromBitmap(rs, overlay); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement()); blur.setInput(overlayAlloc); blur.setRadius(radius); blur.forEach(overlayAlloc); overlayAlloc.copyTo(overlay); view.setBackground(new BitmapDrawable(context.getResources(), overlay)); rs.destroy(); }
From source file:Main.java
public static Bitmap scaleToStretchBitmap(Bitmap dst, InputStream is) { Bitmap src = BitmapFactory.decodeStream(is); return Bitmap.createScaledBitmap(src, dst.getWidth(), dst.getHeight(), true); }