List of usage examples for android.graphics Bitmap getHeight
public final int getHeight()
From source file:Main.java
public static Bitmap LoadFliped(Bitmap src) { Matrix matrix = new Matrix(); matrix.preScale(-1.0f, 1.0f);//from w ww . j a va 2s .c o m return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap handleImageEffect(Bitmap bm, float hue, float saturation, float lum) { Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); ColorMatrix hueMatrix = new ColorMatrix(); hueMatrix.setRotate(0, hue);//from w w w . j a va2 s.c o m hueMatrix.setRotate(1, hue); hueMatrix.setRotate(2, hue); ColorMatrix saturationMatrix = new ColorMatrix(); saturationMatrix.setSaturation(saturation); ColorMatrix lumMatrix = new ColorMatrix(); lumMatrix.setScale(lum, lum, lum, 1); ColorMatrix imageMatrix = new ColorMatrix(); imageMatrix.postConcat(hueMatrix); imageMatrix.postConcat(saturationMatrix); imageMatrix.postConcat(lumMatrix); paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix)); canvas.drawBitmap(bm, 0, 0, paint); return bmp; }
From source file:Main.java
private static Bitmap drawToBitmap(Resources resources, int drawableResourceID, Bitmap bitmap) { Drawable drawable = resources.getDrawable(drawableResourceID); drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight()); drawable.draw(new Canvas(bitmap)); return bitmap; }
From source file:Main.java
public static Bitmap resizeAndCropCenter(Bitmap bitmap, int size, boolean recycle) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); if (w == size && h == size) return bitmap; // scale the image so that the shorter side equals to the target; // the longer side will be center-cropped. float scale = (float) size / Math.min(w, h); Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap)); int width = Math.round(scale * bitmap.getWidth()); int height = Math.round(scale * bitmap.getHeight()); Canvas canvas = new Canvas(target); canvas.translate((size - width) / 2f, (size - height) / 2f); canvas.scale(scale, scale);// www . j av a2 s. c om Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG); canvas.drawBitmap(bitmap, 0, 0, paint); if (recycle) bitmap.recycle(); return target; }
From source file:Main.java
public static Bitmap scaleToStretchBitmap(Bitmap dst, InputStream is) { Bitmap src = BitmapFactory.decodeStream(is); return Bitmap.createScaledBitmap(src, dst.getWidth(), dst.getHeight(), true); }
From source file:Main.java
public static Drawable scaleImage(Drawable drawable, float scaleWidth, float scaleHeight) { Drawable resizedDrawable = null;/* w ww . jav a 2 s .c o m*/ if (drawable != null) { Bitmap bitmapOrg = ((BitmapDrawable) drawable).getBitmap(); int width = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight(); Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); resizedDrawable = new BitmapDrawable(resizedBitmap); } return resizedDrawable; }
From source file:Main.java
/** * This method of image pixelization utilizes the bitmap scaling operations built * into the framework. By downscaling the bitmap and upscaling it back to its * original size (while setting the filter flag to false), the same effect can be * achieved with much better performance. *//*from w ww.j a va 2 s . c o m*/ public static BitmapDrawable builtInPixelization(Context context, float pixelizationFactor, Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int downScaleFactorWidth = (int) (pixelizationFactor * width); downScaleFactorWidth = downScaleFactorWidth > 0 ? downScaleFactorWidth : 1; int downScaleFactorHeight = (int) (pixelizationFactor * height); downScaleFactorHeight = downScaleFactorHeight > 0 ? downScaleFactorHeight : 1; int downScaledWidth = width / downScaleFactorWidth; int downScaledHeight = height / downScaleFactorHeight; Bitmap pixelatedBitmap = Bitmap.createScaledBitmap(bitmap, downScaledWidth, downScaledHeight, false); /* Bitmap's createScaledBitmap method has a filter parameter that can be set to either * true or false in order to specify either bilinear filtering or point sampling * respectively when the bitmap is scaled up or now. * * Similarly, a BitmapDrawable also has a flag to specify the same thing. When the * BitmapDrawable is applied to an ImageView that has some scaleType, the filtering * flag is taken into consideration. However, for optimization purposes, this flag was * ignored in BitmapDrawables before Jelly Bean MR1. * * Here, it is important to note that prior to JBMR1, two bitmap scaling operations * are required to achieve the pixelization effect. Otherwise, a BitmapDrawable * can be created corresponding to the downscaled bitmap such that when it is * upscaled to fit the ImageView, the upscaling operation is a lot faster since * it uses internal optimizations to fit the ImageView. * */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(), pixelatedBitmap); bitmapDrawable.setFilterBitmap(false); return bitmapDrawable; } else { Bitmap upscaled = Bitmap.createScaledBitmap(pixelatedBitmap, width, height, false); return new BitmapDrawable(context.getResources(), upscaled); } }
From source file:Main.java
/** * Returns the in memory size of the given {@link Bitmap}. *///w ww. ja v a 2s .c o m public static int getSize(Bitmap bitmap) { if (Build.VERSION.SDK_INT >= 19) { return bitmap.getAllocationByteCount(); } else { return bitmap.getHeight() * bitmap.getRowBytes(); } }
From source file:Main.java
public static Bitmap toRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float roundPx; float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom; if (width <= height) { roundPx = width / 2;//from w w w . j a v a 2 s. c o m left = 0; top = 0; right = width; bottom = width; height = width; dst_left = 0; dst_top = 0; dst_right = width; dst_bottom = width; } else { roundPx = height / 2; float clip = (width - height) / 2; left = clip; right = width - clip; top = 0; bottom = height; width = height; dst_left = 0; dst_top = 0; dst_right = height; dst_bottom = height; } Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom); final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom); final RectF rectF = new RectF(dst); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, src, dst, paint); return output; }
From source file:Main.java
static Bitmap resizeBitmap(Bitmap bitmap, int maximumDimension, boolean scaleUpIfSmaller) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float newScale; if (Math.max(width, height) <= maximumDimension && !scaleUpIfSmaller) { return bitmap; }/* w w w . j av a2s . co m*/ if (width > height) { newScale = (float) maximumDimension / (float) width; } else { newScale = (float) maximumDimension / (float) height; } Matrix matrix = new Matrix(); matrix.postScale(newScale, newScale); return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); }