List of usage examples for android.graphics Bitmap getHeight
public final int getHeight()
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
/** * 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>.//from w w w. jav a 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
/**Method to get round shaped bitmap. Mostly used for profile pictures * * @param scaleBitmapImage/* w w w . j ava 2s. co m*/ * The source bitmap which has to converted to round shape * @param context * The context * @param targetWidthPixels * The width required for the target or returned bitmap * @param targetHeightPixels * The height required for the target or returned bitmap * @return * round shaped bitmap */ public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, Context context, int targetWidthPixels, int targetHeightPixels) { Bitmap targetBitmap = Bitmap.createBitmap(targetWidthPixels, targetHeightPixels, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(((float) targetWidthPixels - 1) / 2, ((float) targetHeightPixels - 1) / 2, (Math.min(((float) targetWidthPixels), ((float) targetHeightPixels)) / 2), Path.Direction.CCW); canvas.clipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()), new Rect(0, 0, targetWidthPixels, targetHeightPixels), null); return targetBitmap; }
From source file:Main.java
public static Bitmap scaleBitmap(Bitmap bitmap, float scale) { int width = (int) ((float) bitmap.getWidth() * scale); int height = (int) ((float) bitmap.getHeight() * scale); if (bitmap.getWidth() != width || bitmap.getHeight() != height) { return Bitmap.createScaledBitmap(bitmap, width, height, true /* filter */); } else {//from w ww . j a v a2s. c om return bitmap; } }
From source file:Main.java
public static Bitmap scaleWithRatio(Context c, int res, int max) { Bitmap bmp = imageResourceToBitmap(c, res, max); int width = bmp.getWidth(); int height = bmp.getHeight(); // calculate the scale - in this case = 0.4f float scaleHeight = ((float) max) / height; float scaleWidth = ((float) max) / width; // createa matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate the new Bitmap and return it return Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true); }
From source file:Main.java
private static Bitmap rotateBitmap(Bitmap bitmap, int rotate) { if (bitmap == null) { return null; }/* w w w . j ava2 s .c o m*/ int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(rotate); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); }
From source file:Main.java
static private Bitmap smallCoverPostProc(Bitmap smallBitmap) { try {/*from w w w . ja v a 2 s.c o m*/ Bitmap smallBitmapPostProc = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), Bitmap.Config.RGB_565); Canvas canvas = new Canvas(); canvas.setBitmap(smallBitmapPostProc); Paint paint = new Paint(); paint.setAntiAlias(true); Bitmap bitmapToShade = Bitmap.createBitmap(smallBitmap, 2, 2, smallBitmap.getWidth() - 4, smallBitmap.getHeight() - 4); BitmapShader bmShader = new BitmapShader(bitmapToShade, TileMode.CLAMP, TileMode.CLAMP); paint.setShader(bmShader); canvas.drawRoundRect(new RectF(2, 2, smallBitmap.getWidth() - 2, smallBitmap.getHeight() - 2), 4, 4, paint); return smallBitmapPostProc; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap rotateImageView(int angle, Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.postRotate(angle);// w w w . ja va 2 s. c o m return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
From source file:Main.java
private static Bitmap rotateImageView(int angle, Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.postRotate(angle);//ww w . j a va 2 s .com return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap decodeInSampleSize(Bitmap bitmap, int reqWidth, int reqHeight) { if (bitmap.getWidth() >= reqWidth * 2 && bitmap.getHeight() >= reqHeight * 2) { ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayBitmapStream); byte[] byteArray = byteArrayBitmapStream.toByteArray(); bitmap = decodeInSampleSize(byteArray, reqWidth, reqHeight); }/*ww w . ja v a 2 s.c om*/ return bitmap; }