Various photoshop apps are available in android. Various operations like rotating, flipping, mirror image, water image, converting to grayscale are available. Also advanced features like snow effect are also possible.
//Get image set to imageview
Imageview.buildDrawingCache();
bitmap = Imageview.getDrawingCache();
Matrix matrixr = new Matrix();
//Rotate matrix
matrixr.postRotate(270);
bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrixr, true);
Rotate Left
//Get image set to imageview
Imageview.buildDrawingCache();
bitmap = Imageview.getDrawingCache();
Matrix matrixr = new Matrix();
//Rotate matrix
matrixr.postRotate(90);
bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrixr, true);
2. Flip Horizontal
//Get image set to imageview
Imageview.buildDrawingCache();
bitmap = Imageview.getDrawingCache();
Matrix matrixr = new Matrix();
//Scale matr
matrixr.preScale(-1.0f, 1.0f );
bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrixr, true);
3. Gray Scale
public static Bitmap convertToGray(Bitmap src)
{
//setting red, green, blue factors to convert image to grayscale
final double GS_RED = 0.299;
final double GS_GREEN = 0.587;
final double GS_BLUE = 0.114;
//create output bitmap
Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
int A,R,G,B;
int pixel;
int width = src.getWidth();
int height =src.getHeight();
//pixels iteration
for(int x=0;x<width;++x)
{
for(int y=0;y<height;++y)
{
pixel = src.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
// Generating pixels for gray scale image
R = G = B = (int) (G*GS_GREEN + R*GS_RED + B*GS_BLUE);
bmOut.setPixel(x, y, Color.argb(A, R, G, B));
}
}
return bmOut;
}
4.Snow Effect
public static Bitmap applySnowEffect(Bitmap source) {
// get image size
int width = source.getWidth();
int height = source.getHeight();
int[] pixels = new int[width * height];
// get pixel array from source
source.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;
}
- Rotate
- Flip (Mirror image)
- Gray Scale
- Snow Effect
//Get image set to imageview
Imageview.buildDrawingCache();
bitmap = Imageview.getDrawingCache();
Matrix matrixr = new Matrix();
//Rotate matrix
matrixr.postRotate(270);
bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrixr, true);
Rotate Left
//Get image set to imageview
Imageview.buildDrawingCache();
bitmap = Imageview.getDrawingCache();
Matrix matrixr = new Matrix();
//Rotate matrix
matrixr.postRotate(90);
bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrixr, true);
2. Flip Horizontal
//Get image set to imageview
Imageview.buildDrawingCache();
bitmap = Imageview.getDrawingCache();
Matrix matrixr = new Matrix();
//Scale matr
matrixr.preScale(-1.0f, 1.0f );
bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrixr, true);
3. Gray Scale
public static Bitmap convertToGray(Bitmap src)
{
//setting red, green, blue factors to convert image to grayscale
final double GS_RED = 0.299;
final double GS_GREEN = 0.587;
final double GS_BLUE = 0.114;
//create output bitmap
Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
int A,R,G,B;
int pixel;
int width = src.getWidth();
int height =src.getHeight();
//pixels iteration
for(int x=0;x<width;++x)
{
for(int y=0;y<height;++y)
{
pixel = src.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
// Generating pixels for gray scale image
R = G = B = (int) (G*GS_GREEN + R*GS_RED + B*GS_BLUE);
bmOut.setPixel(x, y, Color.argb(A, R, G, B));
}
}
return bmOut;
}
4.Snow Effect
public static Bitmap applySnowEffect(Bitmap source) {
// get image size
int width = source.getWidth();
int height = source.getHeight();
int[] pixels = new int[width * height];
// get pixel array from source
source.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;
}
No comments:
Post a Comment