List of usage examples for android.graphics Bitmap copy
public Bitmap copy(Config config, boolean isMutable)
From source file:Main.java
public static Bitmap setShadow(Bitmap bitmap, int radius) { BlurMaskFilter blurFilter = new BlurMaskFilter(radius, BlurMaskFilter.Blur.OUTER); Paint shadowPaint = new Paint(); shadowPaint.setAlpha(50);//ww w . j a v a 2 s .co m shadowPaint.setColor(0xff424242); shadowPaint.setMaskFilter(blurFilter); int[] offsetXY = new int[2]; Bitmap shadowBitmap = bitmap.extractAlpha(shadowPaint, offsetXY); Bitmap shadowImage32 = shadowBitmap.copy(Bitmap.Config.ARGB_8888, true); Canvas c = new Canvas(shadowImage32); c.drawBitmap(bitmap, -offsetXY[0], -offsetXY[1], null); return shadowImage32; }
From source file:Main.java
public static Bitmap ensureGLCompatibleBitmap(Bitmap bitmap) { if (bitmap == null || bitmap.getConfig() != null) return bitmap; Bitmap newBitmap = bitmap.copy(Config.ARGB_8888, false); bitmap.recycle();/*ww w .ja v a2s . com*/ return newBitmap; }
From source file:Main.java
/** * ATTENTION: DON'T USE THIS METHOD BECAUSE IT HAS BAD PERFORMANCES. * * @param source The original Bitmap./*from w w w.j a v a2 s. c o m*/ * @param color Color to overlay. * @return the result image. */ @Deprecated private static Bitmap overlayColor(Bitmap source, int color) { Bitmap newBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.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:com.ibuildapp.romanblack.MultiContactsPlugin.helpers.Statics.java
public static Bitmap appyColorFilterForResource(Context context, int resourceId, int color, PorterDuff.Mode mode) {// w w w.j a v a 2 s . c o m Bitmap immutable = BitmapFactory.decodeResource(context.getResources(), resourceId); final Bitmap mutable = immutable.copy(Bitmap.Config.ARGB_8888, true); Canvas c = new Canvas(mutable); Paint p = new Paint(); p.setColorFilter(new PorterDuffColorFilter(color, mode)); c.drawBitmap(mutable, 0.f, 0.f, p); return mutable; }
From source file:Main.java
public static Bitmap makeBlur(Context context, Bitmap sentBitmap, int radius) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); final RenderScript rs = RenderScript.create(context); final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius);/*from w w w .j a v a2s.c om*/ script.setInput(input); script.forEach(output); output.copyTo(bitmap); return bitmap; } return null; }
From source file:Main.java
public static Bitmap clearBitmap(Bitmap sourceBitmap) { Bitmap newBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight());/*from w w w . java 2s . c o m*/ Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true); mutableBitmap.eraseColor(Color.TRANSPARENT); return mutableBitmap; }
From source file:Main.java
public static Bitmap createMutableBitmap(Bitmap src) { Bitmap result = null;/*from w w w.j av a2s. c o m*/ if (src == null) { return null; } result = src.copy(Bitmap.Config.ARGB_8888, true); return result; }
From source file:Main.java
public static Bitmap effectWhiten(Bitmap bitmap, int threshold) { if (bitmap == null) { return bitmap; }// w w w . ja v a 2s . c o m Bitmap dst = bitmap.copy(Bitmap.Config.ARGB_8888, true); int height = dst.getHeight(); int width = dst.getWidth(); int[] pixels = new int[(width * height)]; dst.getPixels(pixels, 0, width, 0, 0, width, height); for (int YY = 0; YY < width; ++YY) { for (int XX = 0; XX < height; ++XX) { int bitmapColor = pixels[(YY + XX * width)]; int[] color = { Color.red(bitmapColor), Color.green(bitmapColor), Color.blue(bitmapColor) }; if (color[0] > threshold && color[1] > threshold && color[2] > threshold) { color[0] = 255; color[1] = 255; color[2] = 255; } pixels[(YY + XX * width)] = Color.rgb(color[0], color[1], color[2]); } } dst.setPixels(pixels, 0, width, 0, 0, width, height); return dst; }
From source file:Main.java
/** * Fills the bitmap's pixels of the specified Color to transparency. * /* ww w . j a va 2s . c o m*/ * @param aBitmap bitmap to process * @param aColor color to fill * @return bmp */ @SuppressLint("NewApi") public static Bitmap eraseBG(Bitmap aBitmap, int aColor) { int width = aBitmap.getWidth(); int height = aBitmap.getHeight(); Bitmap b = aBitmap.copy(Config.ARGB_8888, true); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR1) { b.setHasAlpha(true); } int[] pixels = new int[width * height]; aBitmap.getPixels(pixels, 0, width, 0, 0, width, height); for (int i = 0; i < width * height; i++) { if (pixels[i] == aColor) { pixels[i] = 0; } } b.setPixels(pixels, 0, width, 0, 0, width, height); return b; }
From source file:Main.java
/** * Add an alpha channel to the given image if it does not already have one. * //from ww w . j a va2s . c o m * @param image * the image to add an alpha channel to. * @return a copy of the given image with an alpha channel. If the image already have the alpha channel, return the * image itself. */ public static Bitmap imageWithAlpha(Bitmap image) { if (image == null) { return null; } if (image.hasAlpha()) { return image; } return image.copy(Bitmap.Config.ARGB_8888, true); }