List of usage examples for android.graphics Bitmap getWidth
public final int getWidth()
From source file:Main.java
static public Bitmap strechToFill(Bitmap b, int width, int height) { float factorH = height / (float) b.getHeight(); float factorW = width / (float) b.getWidth(); return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factorW), (int) (b.getHeight() * factorH), false); }
From source file:Main.java
public static Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight();/*ww w.j av a2 s . c o m*/ width = bmpOriginal.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(bmpOriginal, 0, 0, paint); return bmpGrayscale; }
From source file:Main.java
public static BitmapDrawable sizeChanger(Context context, ImageView imageView, int sizeOnDps, int orientation) { Drawable drawing = imageView.getDrawable(); if (drawing == null) { return null; }/* w ww .jav a2 s.c om*/ Bitmap bitmap = ((BitmapDrawable) drawing).getBitmap(); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int bounding = dpToPx(250, context); float xScale = ((float) bounding) / width; float yScale = ((float) bounding) / height; float scale = (xScale <= yScale) ? xScale : yScale; Matrix matrix = new Matrix(); matrix.postScale(scale, scale); matrix.postRotate(orientation, imageView.getDrawable().getBounds().width() / 2, imageView.getDrawable().getBounds().height() / 2); Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); width = scaledBitmap.getWidth(); height = scaledBitmap.getHeight(); return new BitmapDrawable(scaledBitmap); }
From source file:Main.java
static public Bitmap strechToFill(Bitmap b, int width, int height) { float factorH = height / (float) b.getHeight(); float factorW = width / (float) b.getWidth(); return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factorW), (int) (b.getHeight() * factorH), true); }
From source file:Main.java
/** * TODO write documentation// w w w . j av a 2 s . c o m * * @param sourceBitmap * @param color * @return */ public static Bitmap overlayColor(Bitmap sourceBitmap, int color) { Bitmap newBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()); Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true); Canvas canvas = new Canvas(mutableBitmap); Paint paint = new Paint(); paint.setAntiAlias(true); ColorFilter filter = new LightingColorFilter(color, 1); paint.setColorFilter(filter); canvas.drawBitmap(mutableBitmap, 0, 0, paint); return mutableBitmap; }
From source file:Main.java
public static Bitmap multiply(Bitmap bitmap1, Bitmap bitmap2) { double alpha = 0.1; int width = bitmap1.getWidth(); int height = bitmap1.getHeight(); Bitmap grayBitmap1 = toGrayScale(bitmap1); Bitmap grayBitmap2 = toGrayScale(bitmap2); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { int value1 = Color.blue(grayBitmap1.getPixel(x, y)); int value2 = Color.blue(grayBitmap2.getPixel(x, y)); int resultValue = (int) (Math.abs((value2 / 255.0) * (value1 / 255.0)) * 255); // resultValue = (resultValue>255/2)?255:0; result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue)); }/* w ww . j a v a 2 s.c o m*/ // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; }
From source file:Main.java
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) { final int reflectionGap = 4; int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1);// w ww . j a v a2s.c om Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w, h / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(w, (h + h / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bitmap, 0, 0, null); Paint deafalutPaint = new Paint(); canvas.drawRect(0, h, w, h + reflectionGap, deafalutPaint); canvas.drawBitmap(reflectionImage, 0, h + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, h, w, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
From source file:Main.java
public static Bitmap emboss(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565); int pixR = 0; int pixG = 0; int pixB = 0; int pixColor = 0; int newR = 0; int newG = 0; int newB = 0; int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); int pos = 0;/*w w w . j av a 2 s . co m*/ for (int i = 1, length = height - 1; i < length; i++) { for (int k = 1, len = width - 1; k < len; k++) { pos = i * width + k; pixColor = pixels[pos]; pixR = Color.red(pixColor); pixG = Color.green(pixColor); pixB = Color.blue(pixColor); pixColor = pixels[pos + 1]; newR = Color.red(pixColor) - pixR + 127; newG = Color.green(pixColor) - pixG + 127; newB = Color.blue(pixColor) - pixB + 127; newR = Math.min(255, Math.max(0, newR)); newG = Math.min(255, Math.max(0, newG)); newB = Math.min(255, Math.max(0, newB)); pixels[pos] = Color.argb(255, newR, newG, newB); } } newBitmap.setPixels(pixels, 0, width, 0, 0, width, height); return newBitmap; }
From source file:Main.java
public static boolean isHorizontalBitmap(Bitmap bitmap) { if (bitmap == null) throw new NullPointerException("Bitmap can not be null!"); return bitmap.getWidth() < bitmap.getHeight(); }
From source file:Main.java
public static int[] getPixels(final Bitmap bit) { if (bit == null) { return null; }/*from w w w . j av a 2 s . c om*/ int width = bit.getWidth(); int height = bit.getHeight(); int pixels[] = new int[width * height]; bit.getPixels(pixels, 0, width, 0, 0, width, height); return pixels; }