Please use below class and pass the bitmap to this function and get return bitmap with Snow effect.
public class NewSnowFilter {
public static final int COLOR_MIN = 0x00;
public static final int COLOR_MAX = 0xFF;
public static Bitmap
applySnowEffect(Bitmap bitmap) {
// get image
size
int width =
bitmap.getWidth();
int height =
bitmap.getHeight();
int[] pixels = new int[width *
height];
// get pixel
array from source
bitmap.getPixels(pixels,
0, width, 0, 0, width, height);
// random
object
Random
random = new Random();
int R, G, B, index
= 0, thresHold = 50;
// iteration
through pixels
for (int y = 0; y <
height; ++y) {
for (int x = 0; x <
width; ++x) {
// get current
index in 2D-matrix
index
= y * width + x;
// get color
R
= Color.red(pixels[index]);
G
= Color.green(pixels[index]);
B
= Color.blue(pixels[index]);
// generate
threshold
thresHold
= random.nextInt(COLOR_MAX);
if (R >
thresHold && G > thresHold && B > thresHold) {
pixels[index]
= Color.rgb(COLOR_MAX, COLOR_MAX, COLOR_MAX);
}
}
}
// output
bitmap
Bitmap
bmOut = Bitmap
.createBitmap(width,
height, Bitmap.Config.RGB_565);
bmOut.setPixels(pixels,
0, width, 0, 0, width, height);
return bmOut;
}
}
By: NovaRadix Technology.
You can view all effect on this photo effect application.
ReplyDeletehttps://play.google.com/store/apps/details?id=com.nova.photo.college.effect