List of usage examples for android.graphics Bitmap getWidth
public final int getWidth()
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float radius) { 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 w ww .java2 s. co m*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels, PorterDuff.Mode mode) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xffffffff; 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; paint.setAntiAlias(true);/*from w w w.jav a2 s .c om*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(mode)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
/** * Method to split an image horizontally into a List * composed by {@code piecesNum} of Bitmaps. * * @param source The source Bitmap./*from w ww . j a va 2s . com*/ * @param piecesNum int that represents the number of pieces. * @return The List of Bitmap's pieces. */ public static List<Bitmap> splitImageHorizontally(Bitmap source, int piecesNum) { List<Bitmap> pieces = new ArrayList<>(); int width = source.getWidth() / piecesNum; int start = 0; for (int i = 0; i < piecesNum; i++) { Bitmap pieceBitmap = Bitmap.createBitmap(source, start, 0, width - 1, source.getHeight() - 1); pieces.add(pieceBitmap); start = (source.getWidth() / piecesNum) * (i + 1); } return pieces; }
From source file:Main.java
public static Bitmap backsheetImage(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); int color;// w w w. j a va 2 s .co m int r, g, b, a; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); int[] oldPx = new int[width * height]; int[] newPx = new int[width * height]; bm.getPixels(oldPx, 0, width, 0, 0, width, height); for (int i = 0; i < oldPx.length; i++) { color = oldPx[i]; r = Color.red(color); g = Color.green(color); b = Color.blue(color); a = Color.alpha(color); r = 255 - r; g = 255 - g; b = 255 - b; if (r > 255) { r = 255; } else if (r < 0) { r = 0; } if (g > 255) { g = 255; } else if (g < 0) { g = 0; } if (b > 255) { b = 255; } else if (b < 0) { b = 0; } newPx[i] = Color.argb(a, r, g, b); } bitmap.setPixels(newPx, 0, width, 0, 0, width, height); return bitmap; }
From source file:Main.java
public static Bitmap olderImage(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); int color;//from w w w . j av a 2 s . c o m int r, g, b, a; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); int[] oldPx = new int[width * height]; int[] newPx = new int[width * height]; bm.getPixels(oldPx, 0, width, 0, 0, width, height); for (int i = 0; i < oldPx.length; i++) { color = oldPx[i]; r = Color.red(color); g = Color.green(color); b = Color.blue(color); a = Color.alpha(color); r = (int) (0.393 * r + 0.769 * g + 0.189 * b); g = (int) (0.349 * r + 0.686 * g + 0.168 * b); b = (int) (0.272 * r + 0.534 * g + 0.131 * b); if (r > 255) { r = 255; } else if (r < 0) { r = 0; } if (g > 255) { g = 255; } else if (g < 0) { g = 0; } if (b > 255) { b = 255; } else if (b < 0) { b = 0; } newPx[i] = Color.argb(a, r, g, b); } bitmap.setPixels(newPx, 0, width, 0, 0, width, height); return bitmap; }
From source file:Main.java
/** * calculate hashcode for a bitmap.//from w ww .ja va2 s . c o m * only calculate part of the first row for performance purpose. * if you want to involve every pixels, use {@link #bitmap2hashFull(Bitmap)}. * @return hash code */ public static long bitmap2hash(Bitmap bitmap) { if (bitmap == null) return 0; long hash = 31; int end = bitmap.getWidth() / 5; for (int x = 0; x < end; x++) { hash *= (bitmap.getPixel(x, 0) + 31); } return hash; }
From source file:Main.java
public static Bitmap handleImagePixelsRelief(Bitmap bm) { Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888); int width = bm.getWidth(); int height = bm.getHeight(); int color = 0, colorBefore = 0; int a, r, g, b; int r1, g1, b1; int[] oldPx = new int[width * height]; int[] newPx = new int[width * height]; bm.getPixels(oldPx, 0, bm.getWidth(), 0, 0, width, height); for (int i = 1; i < width * height; i++) { colorBefore = oldPx[i - 1];/*from w ww . j ava 2s . c o m*/ a = Color.alpha(colorBefore); r = Color.red(colorBefore); g = Color.green(colorBefore); b = Color.blue(colorBefore); color = oldPx[i]; r1 = Color.red(color); g1 = Color.green(color); b1 = Color.blue(color); r = (r - r1 + 127); g = (g - g1 + 127); b = (b - b1 + 127); if (r > 255) { r = 255; } if (g > 255) { g = 255; } if (b > 255) { b = 255; } newPx[i] = Color.argb(a, r, g, b); } bmp.setPixels(newPx, 0, width, 0, 0, width, height); return bmp; }
From source file:Main.java
public static Bitmap get_circular_bitmap(Bitmap bitmap) { Bitmap output;/*from www .j a v a 2 s . c o m*/ if (bitmap.getWidth() > bitmap.getHeight()) { output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); } else { output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), 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()); float r = 0; if (bitmap.getWidth() > bitmap.getHeight()) { r = bitmap.getHeight() / 2; } else { r = bitmap.getWidth() / 2; } paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(r, r, r, 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 bitmapZoomByHeight(Drawable drawable, float newHeight) { Bitmap srcBitmap = drawableToBitmap(drawable); int srcWidth = srcBitmap.getWidth(); int srcHeight = srcBitmap.getHeight(); float scaleHeight = ((float) newHeight) / srcHeight; float scaleWidth = scaleHeight; return bitmapZoomByScale(srcBitmap, scaleWidth, scaleHeight); }
From source file:Main.java
static public Bitmap scaleToFitHeight(Bitmap b, int height) { float factor = height / (float) b.getHeight(); return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factor), height, false); }