List of usage examples for android.graphics Bitmap getWidth
public final int getWidth()
From source file:Main.java
public static Bitmap resizeDownIfTooBig(Bitmap bitmap, int targetSize, boolean recycle) { int srcWidth = bitmap.getWidth(); int srcHeight = bitmap.getHeight(); float scale = Math.max((float) targetSize / srcWidth, (float) targetSize / srcHeight); if (scale > 0.5f) return bitmap; return resizeBitmapByScale(bitmap, scale, recycle); }
From source file:Main.java
public static Bitmap getResizedBitmap(Bitmap image, int maxSize) { if (image == null) return null; int width = image.getWidth(); int height = image.getHeight(); float bitmapRatio = (float) width / (float) height; width = maxSize;/* www.ja v a 2 s . c o m*/ height = (int) (width / bitmapRatio); return Bitmap.createScaledBitmap(image, width, height, true); }
From source file:Main.java
public static Bitmap changeImageColor(Bitmap sourceBitmap, int color) { Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth() - 1, sourceBitmap.getHeight() - 1); Paint p = new Paint(); p.setColor(color);/* www. j av a2s. c om*/ ColorFilter filter = new LightingColorFilter(color, 1); Canvas canvas = new Canvas(resultBitmap); canvas.drawBitmap(resultBitmap, 0, 0, p); return resultBitmap; }
From source file:Main.java
static public Bitmap cropBitmap(Bitmap src, int x, int y, int width, int height, boolean isRecycle) { if (x == 0 && y == 0 && width == src.getWidth() && height == src.getHeight()) { return src; }// w w w .j a v a2s. c om Bitmap dst = Bitmap.createBitmap(src, x, y, width, height); if (isRecycle && dst != src) { src.recycle(); } return dst; }
From source file:Main.java
public static Bitmap setGrayscale(Bitmap source) { int width, height; height = source.getHeight();/* w ww. j a va 2 s.c o m*/ width = source.getWidth(); 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(source, 0, 0, paint); return bmpGrayScale; }
From source file:Main.java
private static boolean calculateIsDark(Bitmap bitmap) { boolean dark = false; float darkThreshold = bitmap.getWidth() * (bitmap.getHeight() / 5) * 0.55f; int darkPixels = 0; int[] pixels = new int[bitmap.getWidth() * (bitmap.getHeight() / 5)]; bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, bitmap.getHeight() / 5 * 4, bitmap.getWidth(), bitmap.getHeight() / 5);//w w w . j a v a 2 s .c o m for (int pixel : pixels) { int r = Color.red(pixel); int g = Color.green(pixel); int b = Color.blue(pixel); double luminance = (0.299 * r + 0.0f + 0.587 * g + 0.0f + 0.114 * b + 0.0f); if (luminance < 150) { darkPixels++; } } if (darkPixels >= darkThreshold) { dark = true; } return dark; }
From source file:Main.java
public static Bitmap resizeDownBySideLength(Bitmap bitmap, int maxLength, boolean recycle) { int srcWidth = bitmap.getWidth(); int srcHeight = bitmap.getHeight(); float scale = Math.min((float) maxLength / srcWidth, (float) maxLength / srcHeight); if (scale >= 1.0f) return bitmap; return resizeBitmapByScale(bitmap, scale, recycle); }
From source file:Main.java
public static Bitmap scaleAndFrame(Bitmap bitmap, int width, int height) { final int bitmapWidth = bitmap.getWidth(); final int bitmapHeight = bitmap.getHeight(); final float scale = Math.min((float) width / (float) bitmapWidth, (float) height / (float) bitmapHeight); final int scaledWidth = (int) (bitmapWidth * scale); final int scaledHeight = (int) (bitmapHeight * scale); final Bitmap decored = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, true); final Canvas canvas = new Canvas(decored); final int offset = (int) (PHOTO_BORDER_WIDTH / 2); sStrokePaint.setAntiAlias(false);//from ww w . j a v a 2s .c om canvas.drawRect(offset, offset, scaledWidth - offset - 1, scaledHeight - offset - 1, sStrokePaint); sStrokePaint.setAntiAlias(true); return decored; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { try {/* w w w .j a v a2 s . c om*/ Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight())); final float roundPx = 15; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.BLACK); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); final Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawBitmap(bitmap, src, rect, paint); return output; } catch (Exception e) { return bitmap; } }
From source file:Main.java
public static Bitmap scaleWithRatio(Context c, int res, int max) { Bitmap bmp = imageResourceToBitmap(c, res, max); int width = bmp.getWidth(); int height = bmp.getHeight(); // calculate the scale - in this case = 0.4f float scaleHeight = ((float) max) / height; float scaleWidth = ((float) max) / width; // createa matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate the new Bitmap and return it return Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true); }