List of usage examples for android.graphics Bitmap getHeight
public final int getHeight()
From source file:Main.java
public static byte[] bitmap2Byte(Bitmap bitmap) { if (bitmap == null) { return null; }//from w w w .j ava 2s .c o m int size = bitmap.getWidth() * bitmap.getHeight(); ByteArrayOutputStream baos = new ByteArrayOutputStream(size); bitmap.compress(CompressFormat.JPEG, 100, baos); return baos.toByteArray(); }
From source file:Main.java
public static Bitmap getRounded(Bitmap bm, int cornerRadiusPx) { int w = bm.getWidth(); int h = bm.getHeight(); Bitmap bmOut = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmOut); Paint paint = new Paint(); paint.setAntiAlias(true);//w ww . j a va2 s . c om paint.setColor(0xff424242); Rect rect = new Rect(0, 0, w, h); RectF rectF = new RectF(rect); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, cornerRadiusPx, cornerRadiusPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bm, rect, rect, paint); return bmOut; }
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bm, int direction) { Bitmap returnBm;/*from w w w. j av a 2 s.c om*/ int w = bm.getWidth(); int h = bm.getHeight(); Matrix matrix = new Matrix(); if (direction == ROTATE_LEFT) { matrix.postRotate(-90); } else if (direction == ROTATE_RIGHT) { matrix.postRotate(90); } returnBm = Bitmap.createBitmap(bm, 0, 0, w, h, matrix, true); if (bm != returnBm) { bm.recycle(); } return returnBm; }
From source file:Main.java
public static Bitmap getPaintedBitmap(Bitmap bitmap, Paint paint, boolean deleteOld) { final Bitmap colorBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); final Canvas c = new Canvas(colorBitmap); c.drawBitmap(bitmap, 0, 0, paint);/*ww w.j a v a 2 s . co m*/ if (deleteOld) { bitmap.recycle(); } return colorBitmap; }
From source file:Main.java
public static int[] extractPixels(final Bitmap bitmap) { final int w = bitmap.getWidth(); final int h = bitmap.getHeight(); final int[] colors = new int[w * h]; bitmap.getPixels(colors, 0, w, 0, 0, w, h); return colors; }
From source file:Main.java
public static Bitmap toThreshold(Bitmap bmpOriginal) { int imageWidth = bmpOriginal.getWidth(); int imageHeight = bmpOriginal.getHeight(); Bitmap bmpThreshold = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.RGB_565); int[] buffer = new int[imageWidth]; int grayVal;// w w w .ja v a 2 s .com for (int row = 0; row < imageHeight; row++) { for (int col = 0; col < imageWidth; col++) { grayVal = rgbToGray(bmpOriginal.getPixel(col, row)); if (grayVal > 125) buffer[col] = Color.rgb(255, 255, 255); else buffer[col] = Color.rgb(0, 0, 0); } bmpThreshold.setPixels(buffer, 0, imageWidth, 0, row, imageWidth, 1); } return bmpThreshold; }
From source file:Main.java
public static Bitmap getImageThumbnail(Bitmap input) { int desiredWidth = 500; Float width = new Float(input.getWidth()); Float height = new Float(input.getHeight()); Float ratio = width / height; return Bitmap.createScaledBitmap(input, (int) (desiredWidth * ratio), desiredWidth, false); }
From source file:Main.java
public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidht = ((float) w) / width; float scaleHeight = ((float) h) / height; matrix.postScale(scaleWidht, scaleHeight); Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return newbmp; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap srcBitmap, float radius) { Bitmap resultBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Bitmap.Config.ARGB_8888);//from w ww . ja v a 2 s .com Canvas canvas = new Canvas(resultBitmap); Paint paint = new Paint(); Rect rect = new Rect(0, 0, srcBitmap.getWidth(), srcBitmap.getHeight()); RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(0xBDBDBE); canvas.drawRoundRect(rectF, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(srcBitmap, rect, rect, paint); return resultBitmap; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { 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);//from w ww.j a va2s . c om 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); return output; }