List of usage examples for android.graphics Bitmap getConfig
public final Config getConfig()
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap gray(Bitmap bmImage) { Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig()); // The W3C Algorithm double intensityRed = 0.299; double intensityGreen = 0.587; double intensityBlue = 0.114; for (int i = 0; i < bmImage.getWidth(); i++) { for (int j = 0; j < bmImage.getHeight(); j++) { int p = bmImage.getPixel(i, j); int r = Color.red(p); int g = Color.green(p); int b = Color.blue(p); /*/*from w w w. ja v a2 s . com*/ * r = g = b = (int) (r * intensityRed + g * intensityGreen + b intensityBlue); * * bmTemp.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b)); */ // int rgb = (r * 77 + g * 151 + b * 28) >> 8; // NTSC luma int rgb = (int) Math.sqrt(r * r * 0.241 + g * g * 0.691 + b * b * 0.068); // HSP, where the P stands for Perceived brightness bmTemp.setPixel(i, j, (p & 0xff000000) | (rgb << 16) | (rgb << 8) | rgb); } } return bmTemp; }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap cartoonify(Bitmap bmImage, int blurRadius) { Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig()); Bitmap bmGrey = gray(bmImage);/* ww w . j a v a2 s . c o m*/ Bitmap bmInverted = invert(bmGrey); Bitmap bmBlurred = fastblur(bmInverted, blurRadius); Bitmap bmColorDodgeBlend = colorDodgeBlend(bmBlurred, bmGrey); Bitmap bmSrcBlurred = fastblur(bmImage, blurRadius); Bitmap bmCartoon = getCartoonizedBitmap(bmSrcBlurred, bmColorDodgeBlend, 90, 90, 90, 10, 10); return bmCartoon; }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap bright(Bitmap bmImage, int brightness) { Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig()); for (int i = 0; i < bmImage.getWidth(); i++) { for (int j = 0; j < bmImage.getHeight(); j++) { int p = bmImage.getPixel(i, j); int r = Color.red(p); int g = Color.green(p); int b = Color.blue(p); int alpha = Color.alpha(p); r += brightness;/*ww w . j a v a 2 s . co m*/ g += brightness; b += brightness; alpha += brightness; r = r < 0 ? 0 : (r > 255 ? 255 : r); g = g < 0 ? 0 : (g > 255 ? 255 : g); b = b < 0 ? 0 : (b > 255 ? 255 : b); alpha = alpha < 0 ? 0 : (alpha > 255 ? 255 : alpha); bmTemp.setPixel(i, j, Color.argb(alpha, r, g, b)); } } return bmTemp; }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap tint(Bitmap bmImage, int degree) { Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig()); double angle = (3.14159d * (double) degree) / 180.0d; int S = (int) (256.0d * Math.sin(angle)); int C = (int) (256.0d * Math.cos(angle)); for (int i = 0; i < bmImage.getWidth(); i++) { for (int j = 0; j < bmImage.getHeight(); j++) { int p = bmImage.getPixel(i, j); int r = Color.red(p); int g = Color.green(p); int b = Color.blue(p); // int alpha = Color.alpha(p); int RY = (70 * r - 59 * g - 11 * b) / 100; int BY = (-30 * r - 59 * g + 89 * b) / 100; int Y = (30 * r + 59 * g + 11 * b) / 100; int RYY = (S * BY + C * RY) / 256; int BYY = (C * BY - S * RY) / 256; int GYY = (-51 * RYY - 19 * BYY) / 100; r = Y + RYY;//from ww w .j a v a 2 s . c o m r = (r < 0) ? 0 : ((r > 255) ? 255 : r); g = Y + GYY; g = (g < 0) ? 0 : ((g > 255) ? 255 : g); b = Y + BYY; b = (b < 0) ? 0 : ((b > 255) ? 255 : b); bmTemp.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b)); } } return bmTemp; }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap myTest(Bitmap bmImage, int amplitude) { Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig()); // Bitmap bmTemp = bmImage.copy(Config.ARGB_8888, true); for (int i = 0; i < bmImage.getWidth(); i++) { for (int j = 0; j < bmImage.getHeight(); j++) { int sign; if (i <= bmImage.getWidth() / 2 || j <= bmImage.getHeight() / 2) sign = 1;/*from w w w .j ava 2 s . co m*/ else sign = -1; int ki = (int) (i + amplitude * sign * Math.cos(j * 2 * Math.PI / bmImage.getHeight())); int kj = (int) (j + amplitude * sign * Math.cos(i * 2 * Math.PI / bmImage.getWidth())); // * Math.tan(i * 2 * Math.PI / bmImage.getWidth())); // * Math.sin(i * 2 * Math.PI / bmImage.getWidth())); // k = Math.max(0, k); // k = Math.min(bmImage.getHeight() - 1, k); if (ki >= 0 && ki < bmImage.getWidth() && kj >= 0 && kj < bmImage.getHeight()) bmTemp.setPixel(i, j, bmImage.getPixel(ki, kj)); else bmTemp.setPixel(i, j, 0x00ffffff); } // /for(j) } // /for(i) return bmTemp; }
From source file:com.fastbootmobile.encore.app.fragments.AlbumViewFragment.java
/** * Sets the arguments for this fragment/* w ww . ja va 2 s . com*/ * @param hero The hero header image bitmap * @param extras The extras contained in the Intent that started the parent activity */ public void setArguments(Bitmap hero, Bundle extras) { if (hero != null) { mHeroImage = hero.copy(hero.getConfig(), false); } mBackgroundColor = extras.getInt(AlbumActivity.EXTRA_BACKGROUND_COLOR, 0xFF333333); String albumRef = extras.getString(AlbumActivity.EXTRA_ALBUM); ProviderIdentifier provider = ProviderIdentifier .fromSerialized(extras.getString(AlbumActivity.EXTRA_PROVIDER)); mAlbum = ProviderAggregator.getDefault().retrieveAlbum(albumRef, provider); if (mAlbum == null) { Log.e(TAG, "Album isn't in cache and provider returned null!"); } }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap mozac(Bitmap bmImage, int level) { Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig()); for (int i = 0; i < bmImage.getWidth(); i += level) { for (int j = 0; j < bmImage.getHeight(); j += level) { int p = 0; int r = 0; int g = 0; int b = 0; // compute neighboring area index int kx_start = i - level; int kx_end = i + level; int ky_start = j - level; int ky_end = j + level; // filter out boundary index kx_start = Math.max(0, kx_start); kx_end = Math.min(bmImage.getWidth() - 1, kx_end); ky_start = Math.max(0, ky_start); ky_end = Math.min(bmImage.getHeight() - 1, ky_end); // summing and averaging color value within the neighboring area for (int ki = kx_start; ki <= kx_end; ki++) { for (int kj = ky_start; kj <= ky_end; kj++) { p = bmImage.getPixel(ki, kj); r += Color.red(p); g += Color.green(p); b += Color.blue(p); }// w w w .j ava 2s .c om } int n = (kx_end - kx_start + 1) * (ky_end - ky_start + 1); r /= n; g /= n; b /= n; // copy color value to each pixel on neighboring area for (int kx = kx_start; kx <= kx_end; kx++) { for (int ky = ky_start; ky <= ky_end; ky++) { bmTemp.setPixel(kx, ky, Color.argb(Color.alpha(p), r, g, b)); } } } // /for(j) } // /for(i) return bmTemp; }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap bulging(Bitmap bmImage, int radius, int pointX, int pointY) { Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig()); // Bitmap bmTemp = bmImage.copy(Config.ARGB_8888, true); for (int i = 0; i < bmImage.getWidth(); i++) { for (int j = 0; j < bmImage.getHeight(); j++) { // get center point double cx = pointX; // bmImage.getWidth() / 2; double cy = pointY; // bmImage.getHeight() / 2; // compute distance to center point double r = Math.sqrt(Math.pow(i - cx, 2) + Math.pow(j - cy, 2)); // compute angle atan2(y, x) in range (-PI..PI] n polar coordinate system double a = Math.atan2(j - cy, i - cx); // rn = r ^ k, k=1..2 double rn = Math.pow(r, radius / 10.0) / (radius); // compute mapping point and then shift to center point int kx = (int) (rn * Math.cos(a) + cx); int ky = (int) (rn * Math.sin(a) + cy); if (kx >= 0 && kx < bmImage.getWidth() && ky >= 0 && ky < bmImage.getHeight()) bmTemp.setPixel(i, j, bmImage.getPixel(kx, ky)); else/*from www .j a v a 2 s .c om*/ bmTemp.setPixel(i, j, 0x00ffffff); } // /for(j) } // /for(i) return bmTemp; }
From source file:com.lithidsw.wallbox.app.wallsnap.WallSnapFragment.java
Bitmap BlurImage(Bitmap input, int radius) { RenderScript rsScript = RenderScript.create(mActivity); Allocation alloc = Allocation.createFromBitmap(rsScript, input); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rsScript, alloc.getElement()); blur.setRadius(radius + 1);/* w w w.j ava 2s. c om*/ blur.setInput(alloc); Bitmap result = Bitmap.createBitmap(input.getWidth(), input.getHeight(), input.getConfig()); Allocation outAlloc = Allocation.createFromBitmap(rsScript, result); blur.forEach(outAlloc); outAlloc.copyTo(result); rsScript.destroy(); return result; }
From source file:io.jawg.osmcontributor.ui.utils.BitmapHandler.java
/** * Get the white icon corresponding to a poiType. * * @param poiType the PoiType or null for notes. * @return The white icon./*from ww w . j av a 2s . c o m*/ */ public Drawable getIconWhite(PoiType poiType) { Bitmap myBitmap = BitmapFactory.decodeResource(context.getResources(), poiType == null ? R.drawable.open_book : getIconDrawableId(poiType)); myBitmap = myBitmap.copy(myBitmap.getConfig(), true); int[] allpixels = new int[myBitmap.getHeight() * myBitmap.getWidth()]; myBitmap.getPixels(allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight()); for (int i = 0; i < myBitmap.getHeight() * myBitmap.getWidth(); i++) { if (allpixels[i] != 0) { int A = Color.alpha(allpixels[i]); // inverting byte for each R/G/B channel int R = 255 - Color.red(allpixels[i]); int G = 255 - Color.green(allpixels[i]); int B = 255 - Color.blue(allpixels[i]); // set newly-inverted pixel to output image allpixels[i] = Color.argb(A, R, G, B); } } myBitmap.setPixels(allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight()); return new BitmapDrawable(context.getResources(), myBitmap); }