List of usage examples for android.graphics Bitmap getWidth
public final int getWidth()
From source file:Main.java
/** * Gets the rounded corner bitmap.//from ww w. j a v a 2s .com * * @param bitmap the bitmap * @return the rounded corner bitmap */ public static Bitmap getRoundedCornerBitmap(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()); final RectF rectF = new RectF(rect); final float roundPx = 12; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap resizeBitmap(Bitmap src, int max) { if (src == null) return null; int width = src.getWidth(); int height = src.getHeight(); float rate = 0.0f; if (width > height) { rate = max / (float) width; height = (int) (height * rate); width = max;/*from ww w. ja v a 2 s .c o m*/ } else { rate = max / (float) height; width = (int) (width * rate); height = max; } return Bitmap.createScaledBitmap(src, width, height, true); }
From source file:Main.java
private static Bitmap rotateBitmap(Bitmap bitmap, int rotate) { if (bitmap == null) { return null; }/*ww w . j a v a2 s . co m*/ int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(rotate); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); }
From source file:Main.java
/** * Converts the supplied byte[] to a Bitmap at 75% compression * * @param bytes the bitmap's bytes//ww w .j a v a2 s .c o m * @return the Bitmap */ public static synchronized Bitmap asBitmap(byte[] bytes) { Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); return Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 4, bmp.getHeight() / 4, true); }
From source file:Main.java
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, int width) { // TODO Auto-generated method stub int targetWidth = width; int targetHeight = width; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2, (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW); canvas.clipPath(path);//from w w w .j av a2s . c o m Bitmap sourceBitmap = scaleBitmapImage; canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()), new Rect(0, 0, targetWidth, targetHeight), null); return targetBitmap; }
From source file:Main.java
/** * Copy the red channel to a new Bitmap's alpha channel. The old * one will be recycled./*from w ww . ja v a 2 s . com*/ */ static Bitmap redToAlpha(Bitmap src, boolean recycle) { Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888); float[] matrix = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; Paint paint = new Paint(); paint.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(matrix))); Canvas canvas = new Canvas(dest); canvas.setDensity(Bitmap.DENSITY_NONE); canvas.drawBitmap(src, 0, 0, paint); if (recycle) src.recycle(); return dest; }
From source file:Main.java
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) { Bitmap sbmp;/*from www. j a va 2s .c om*/ 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(Paint.ANTI_ALIAS_FLAG); 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
/** * Converts a bitmap image to LCD screen data and returns the screen data as bytes. * @param buffer The screen's data buffer. * @param offset The byte offset to start writing screen bitmap data at. * @param bmp The bitmap image that you want to convert to screen data. * @param drawWhite Set to true to draw white pixels, false to draw pixels based on gradient. * @return A byte array with pixel data for the SSD1306. *//*from w ww. ja va 2s . c o m*/ public static void bmpToBytes(byte[] buffer, int offset, Bitmap bmp, boolean drawWhite) { int width = bmp.getWidth(); int height = bmp.getHeight(); // Each byte stored in memory represents 8 vertical pixels. As such, you must fill the // memory with pixel data moving vertically top-down through the image and scrolling // across, while appending the vertical pixel data by series of 8. for (int y = 0; y < height; y += 8) { for (int x = 0; x < width; x++) { int bytePos = (offset + x) + ((y / 8) * width); for (int k = 0; k < 8; k++) { if ((k + y < height) && (bytePos < buffer.length)) { int pixel = bmp.getPixel(x, y + k); if (!drawWhite) { // Look at Alpha channel instead if ((pixel & 0xFF) > GRADIENT_CUTOFF) { buffer[bytePos] |= 1 << k; } } else { if (pixel == -1) { // Only draw white pixels buffer[bytePos] |= 1 << k; } } } } } } }
From source file:Main.java
public static Bitmap getMosaic(Bitmap bmpOriginal) { int width = bmpOriginal.getWidth(); int height = bmpOriginal.getHeight(); int sizeW = width / STEP; int sizeH = height / STEP; int resultW = sizeW * STEP; int resultH = sizeH * STEP; Bitmap bmpMosaic = Bitmap.createBitmap(resultW, resultH, Bitmap.Config.RGB_565); int col;// w w w . j a v a 2 s . co m for (int i = 0; i < sizeH; i++) for (int j = 0; j < sizeW; j++) { col = computeAverageColor(j, i, bmpOriginal); fillRigeon(col, j, i, bmpMosaic); } return bmpMosaic; }
From source file:Main.java
public static Bitmap getCircleBitmap(Bitmap bitmap) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.RED; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); //final Paint paintBorder = new Paint(); // paintBorder.setColor(Color.GREEN); //paintBorder.setShadowLayer(4.0f, 0.0f, 2.0f, Color.BLACK); //BitmapShader shader = new BitmapShader(Bitmap.createScaledBitmap(output, canvas.getWidth(), canvas.getHeight(), false), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); //paint.setShader(shader); paint.setAntiAlias(true);// w w w. j a v a2s . c om //paintBorder.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); //int circleCenter = bitmap.getWidth() / 2; //int borderWidth = 2; //canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter + borderWidth - 4.0f, paintBorder); //canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter - 4.0f, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); //canvas.drawBitmap(bitmap, circleCenter + borderWidth, circleCenter + borderWidth, paint); bitmap.recycle(); return output; }