List of usage examples for android.graphics Bitmap getHeight
public final int getHeight()
From source file:Main.java
public static Bitmap resize(Bitmap bmp, int width, int height) { float sx = (width * 1.0f) / bmp.getWidth(); float sy = (height * 1.0f) / bmp.getHeight(); Matrix matrix = new Matrix(); matrix.postScale(sx, sy);/*from w w w .j a v a 2 s.c om*/ return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap scaleBitmap(Bitmap srcBmp, int iWidth, int iHeight) { float fWidth = srcBmp.getWidth(); float fHeight = srcBmp.getHeight(); if (fWidth > iWidth) { float mWidth = (float) (fWidth / 100); float fScale = (float) (iWidth / mWidth); fWidth *= (fScale / 100);/* w ww. java 2 s .c o m*/ fHeight *= (fScale / 100); } else if (fHeight > iHeight) { float mHeight = (float) (fHeight / 100); float fScale = (float) (iHeight / mHeight); fWidth *= (fScale / 100); fHeight *= (fScale / 100); } return Bitmap.createScaledBitmap(srcBmp, (int) fWidth, (int) fHeight, true); }
From source file:Main.java
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) { Bitmap sbmp;//from w w w . j a va 2 s. c o m if (bmp.getWidth() != radius || bmp.getHeight() != radius) sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false); else sbmp = bmp; Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); //final int color = 0xffa19774; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight()); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.parseColor("#BAB399")); canvas.drawCircle(sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(sbmp, rect, rect, paint); return output; }
From source file:Main.java
/** * Returns semi-rounded bitmap. This is used for displaying atn promotion images. * /*from w w w . j a v a2 s .co m*/ * @param context * @param input * @return */ public static Bitmap getSemiRoundedBitmap(Context context, Bitmap input) { Bitmap output = Bitmap.createBitmap(input.getWidth(), input.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, input.getWidth(), input.getHeight()); final RectF rectF = new RectF(rect); //make sure that our rounded corner is scaled appropriately final float roundPx = densityMultiplier * 10; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); //draw rectangles over the corners we want to be square canvas.drawRect(input.getWidth() / 2, 0, input.getWidth(), input.getHeight() / 2, paint); canvas.drawRect(input.getWidth() / 2, input.getHeight() / 2, input.getWidth(), input.getHeight(), paint); paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, 0, 0, paint); input.recycle(); return output; }
From source file:Main.java
private static List<int[]> getPixels(Bitmap image) { int width = image.getWidth(); int height = image.getHeight(); List<int[]> res = new ArrayList<>(); List<Integer> t = new ArrayList<>(); for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { if (!image.isRecycled()) t.add(image.getPixel(col, row)); }//w ww.ja va 2 s . c om } for (int i = 0; i < t.size(); i += 10) { int[] rr = new int[3]; int argb = t.get(i); rr[0] = (argb >> 16) & 0xFF; rr[1] = (argb >> 8) & 0xFF; rr[2] = (argb) & 0xFF; if (!(rr[0] > 250 && rr[1] > 250 && rr[2] > 250)) { res.add(rr); } } return res; }
From source file:Main.java
/** * Method to combine images side by side. * * @param leftBmp The left Bitmap.// ww w . j a v a 2 s. c o m * @param rightBmp The right Bitmap. * @return A Bitmap with left and right bitmap are glued side by side. */ public static Bitmap combineImagesSideBySide(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 getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { return getRoundedCornerBitmap(bitmap, roundPx, bitmap.getWidth(), bitmap.getHeight()); }
From source file:Main.java
/** * Return histogram of grayscaled image/*w w w .j a va2 s. c o m*/ */ public static int[] getHistogram(Bitmap bmp) { int[] histogram = new int[256]; int width = bmp.getWidth(); int height = bmp.getHeight(); int[] pixels = new int[width * height]; bmp.getPixels(pixels, 0, width, 0, 0, width, height); for (int i = 0; i < width * height; i++) { int c = Color.red(pixels[i]); histogram[c] += 1; } return histogram; }
From source file:Main.java
public static Bitmap handleImagePixelsOldPhoto(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; int r, g, b, a, 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 = 0; i < width * height; i++) { color = oldPx[i];//from w ww . j av a2s . c o m a = Color.alpha(color); r = Color.red(color); g = Color.green(color); b = Color.blue(color); r1 = (int) (0.393 * r + 0.769 * g + 0.189 * b); g1 = (int) (0.349 * r + 0.686 * g + 0.168 * b); b1 = (int) (0.272 * r + 0.534 * g + 0.131 * b); if (r1 > 255) { r1 = 255; } if (g1 > 255) { g1 = 255; } if (b1 > 255) { b1 = 255; } newPx[i] = Color.argb(a, r1, g1, b1); } bmp.setPixels(newPx, 0, width, 0, 0, width, height); return bmp; }
From source file:Main.java
public static int hashBitmap(Bitmap bitmap) { int hash_result = 0; int w = bitmap.getWidth(); int h = bitmap.getHeight(); hash_result = (hash_result << 7) ^ h; hash_result = (hash_result << 7) ^ w; for (int pixel = 0; pixel < 20; ++pixel) { int x = (pixel * 50) % w; int y = (pixel * 100) % h; hash_result = (hash_result << 7) ^ bitmap.getPixel(x, y); }/*from w ww . ja va 2s. c o m*/ return hash_result; }