List of usage examples for android.graphics Bitmap getHeight
public final int getHeight()
From source file:Main.java
public static Bitmap greyScale(Bitmap source) { int width = source.getWidth(); int height = source.getHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); ColorMatrix saturation = new ColorMatrix(); saturation.setSaturation(0f);//from w ww. j av a 2 s. c om Paint paint = new Paint(); paint.setColorFilter(new ColorMatrixColorFilter(saturation)); canvas.drawBitmap(source, 0, 0, paint); source.recycle(); if (source != bitmap) { source.recycle(); } return bitmap; }
From source file:Main.java
/** * Method to combine two images side by side. * * @param leftBmp The left Bitmap./*from w w w. j a v a2 s . co m*/ * @param rightBmp The right Bitmap. * @return A Bitmap with left and right bitmap are glued side by side. */ public static Bitmap combineTwoImagesSideBySide(Bitmap leftBmp, Bitmap rightBmp) { int width; int height = leftBmp.getHeight(); if (leftBmp.getWidth() > rightBmp.getWidth()) { width = leftBmp.getWidth() + rightBmp.getWidth(); } else { width = rightBmp.getWidth() + rightBmp.getWidth(); } Bitmap cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas comboImage = new Canvas(cs); comboImage.drawBitmap(leftBmp, 0f, 0f, null); comboImage.drawBitmap(rightBmp, leftBmp.getWidth(), 0f, null); return cs; }
From source file:Main.java
public static Bitmap GetBitmapClippedCircle(Bitmap bitmap) { final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Path path = new Path(); path.addCircle((float) (width / 2), (float) (height / 2), (float) Math.min(width, (height / 2)), Path.Direction.CCW);/* w w w . j a va 2 s . c om*/ final Canvas canvas = new Canvas(outputBitmap); canvas.clipPath(path); canvas.drawBitmap(bitmap, 0, 0, null); return outputBitmap; }
From source file:Main.java
/** * Fill the hole in the image (version 2) *//* w ww . j a v a 2s .c om*/ public static void fillHole2(Bitmap bmp) { for (int j = 1; j < bmp.getWidth(); j++) { for (int i = 1; i < bmp.getHeight() - 1; i++) { if ((bmp.getPixel(i, j) == Color.TRANSPARENT) && (bmp.getPixel(i + 1, j) != Color.TRANSPARENT)) { bmp.setPixel(i, j, bmp.getPixel(i + 1, j)); // set to the next-below pixel } } } }
From source file:Main.java
public static Bitmap convertToBlackWhite(Bitmap bmp) { int width = bmp.getWidth(); int height = bmp.getHeight(); int[] pixels = new int[width * height]; bmp.getPixels(pixels, 0, width, 0, 0, width, height); int alpha = 0xFF << 24; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int grey = pixels[width * i + j]; int red = ((grey & 0x00FF0000) >> 16); int green = ((grey & 0x0000FF00) >> 8); int blue = (grey & 0x000000FF); grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11); grey = alpha | (grey << 16) | (grey << 8) | grey; pixels[width * i + j] = grey; }//from ww w . j av a 2s . c om } Bitmap newBmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); newBmp.setPixels(pixels, 0, width, 0, 0, width, height); return ThumbnailUtils.extractThumbnail(newBmp, 380, 460); }
From source file:Main.java
public static void invertImage(Bitmap b) { int A, R, G, B; int pixelColor; int height = b.getHeight(); int width = b.getWidth(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { pixelColor = b.getPixel(x, y); A = Color.alpha(pixelColor); R = 255 - Color.red(pixelColor); G = 255 - Color.green(pixelColor); B = 255 - Color.blue(pixelColor); b.setPixel(x, y, Color.argb(A, R, G, B)); }//from www.ja v a 2s. c om } }
From source file:Main.java
public static Bitmap getCroppedBitmap(Bitmap bitmap) { 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()); paint.setAntiAlias(true);/*from ww w . j a v a2 s . c o m*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); // canvas.drawRoundRect(rectF, roundPx, roundPx, paint); canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); // return _bmp; return output; }
From source file:Main.java
public static Bitmap getScaled(Bitmap bm, int sidePx, boolean max) { float w = bm.getWidth(); float h = bm.getHeight(); float wRatio = sidePx / w; float hRatio = sidePx / h; float ratio = max ? Math.min(wRatio, hRatio) : Math.max(wRatio, hRatio); w = ratio * w;//from www. ja v a 2s . c om h = ratio * h; return Bitmap.createScaledBitmap(bm, (int) w, (int) h, true); }
From source file:Main.java
public static Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight(); width = bmpOriginal.getWidth();//from w w w . ja v a 2 s . c o m try { Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 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; } catch (OutOfMemoryError e) { return bmpOriginal; } }
From source file:Main.java
/** * Method to remove colors in a Bitmap, creating a gray scale image. * * @param source The original Bitmap.//from w w w .ja va2 s .c o m * @return The gray scale Bitmap. */ public static Bitmap toGrayscale(Bitmap source) { Bitmap bmpGrayscale = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmpGrayscale); canvas.drawBitmap(source, 0, 0, getGrayScalePaint()); return bmpGrayscale; }