List of usage examples for android.graphics Bitmap getHeight
public final int getHeight()
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bitmap, int rotate) { if (bitmap == null) return null; int w = bitmap.getWidth(); int h = bitmap.getHeight(); // Setting post rotate to 90 Matrix mtx = new Matrix(); mtx.postRotate(rotate);//from w w w. j a v a2 s . c om return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); }
From source file:Main.java
public static Bitmap emboss(Bitmap bmp) { int width = bmp.getWidth(); int height = bmp.getHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); int pixR = 0; int pixG = 0; int pixB = 0; int pixColor = 0; int newR = 0; int newG = 0; int newB = 0; int[] pixels = new int[width * height]; bmp.getPixels(pixels, 0, width, 0, 0, width, height); int pos = 0;// w ww. j a v a 2 s. c o m for (int i = 1, length = height - 1; i < length; i++) { for (int k = 1, len = width - 1; k < len; k++) { pos = i * width + k; pixColor = pixels[pos]; pixR = Color.red(pixColor); pixG = Color.green(pixColor); pixB = Color.blue(pixColor); pixColor = pixels[pos + 1]; newR = Color.red(pixColor) - pixR + 127; newG = Color.green(pixColor) - pixG + 127; newB = Color.blue(pixColor) - pixB + 127; newR = Math.min(255, Math.max(0, newR)); newG = Math.min(255, Math.max(0, newG)); newB = Math.min(255, Math.max(0, newB)); pixels[pos] = Color.argb(255, newR, newG, newB); } } bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { 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); paint.setAntiAlias(true);//from ww w. j av 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(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Rect getBitmapRectCenterInside(Bitmap bitmap, View view) { int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); int viewWidth = view.getWidth(); int viewHeight = view.getHeight(); return getBitmapRectCenterInsideHelper(bitmapWidth, bitmapHeight, viewWidth, viewHeight); }
From source file:Main.java
public static Bitmap LoadFlipedVertical(Bitmap src) { Matrix matrix = new Matrix(); matrix.preScale(1.0f, -1.0f);/* www. j av a 2 s . c o m*/ return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); }
From source file:Main.java
/** * Return rounded bitmap with top left corner as rounded using specified bitmap and bitmap size in pixels. * /*from w w w . jav a2s .c om*/ * @param bitmap to make rounded * @param pixels size of bitmap * @return slightly rounded bitmap. */ public static Bitmap getRoundedTopLeftCornerBitmap(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; final Rect topRightRect = new Rect(bitmap.getWidth() / 2, 0, bitmap.getWidth(), bitmap.getHeight() / 2); final Rect bottomRect = new Rect(0, bitmap.getHeight() / 2, bitmap.getWidth(), bitmap.getHeight()); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); // Fill in upper right corner canvas.drawRect(topRightRect, paint); // Fill in bottom corners canvas.drawRect(bottomRect, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap getCircleBitmap(Bitmap bitmap, boolean recycleable) { 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 w w . j a v a2 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); if (recycleable) { bitmap.recycle(); } return output; }
From source file:Main.java
/** * scale image/* w w w . jav a2s. co m*/ * @param org * @param newWidth * @param newHeight * @return */ public static Bitmap scaleImageTo(Bitmap org, int newWidth, int newHeight) { return scaleImage(org, (float) newWidth / org.getWidth(), (float) newHeight / org.getHeight()); }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { 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);/* ww w. j av a2 s . c o m*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, (float) pixels, (float) pixels, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static boolean isHorizontalBitmap(Bitmap bitmap) { if (bitmap == null) throw new NullPointerException("Bitmap can not be null!"); return bitmap.getWidth() < bitmap.getHeight(); }