Showing posts with label imageview. Show all posts
Showing posts with label imageview. Show all posts

Tuesday, 27 August 2013

Before Pixel Color Replacement

Change/Replacement/Remove pixel colors in ImageView

After Pixel Color Replacement

Change/Replacement/Remove pixel colors in ImageView

Create new Android Project
Project Name: PlayingwithBitmap
Build Target: Android 2.3.3   //or greater than that
Application Name: PlayingwithBitmap
Package Name: com.shaikhhamadali.blogspot.playingwithbitmap
Create Activity: Main
Min SDK: 10 // or greater than that

  1. create main layout:
  • One image view to display the image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff" >

    <ImageView
        android:id="@+id/imViewAndroid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/car" />

</RelativeLayout>

 2. code of main activity:

package com.shaikhhamadali.blogspot.playingwithbitmaps;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.Menu;
import android.widget.ImageView;

public class Main extends Activity {
    ImageView imViewAndroid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
          Bitmap b=replaceColor(BitmapFactory.decodeResource(getResources(), R.drawable.basic),Color.YELLOW,Color.MAGENTA);
  imViewAndroid.setImageBitmap(b);
  
 }
 public Bitmap replaceColor(Bitmap src,int fromColor, int targetColor) {
        if(src == null) {
            return null;
        }
     // Source image size 
        int width = src.getWidth();
        int height = src.getHeight();
        int[] pixels = new int[width * height];
        //get pixels
        src.getPixels(pixels, 0, width, 0, 0, width, height);
 
        for(int x = 0; x < pixels.length; ++x) {
            pixels[x] = (pixels[x] == fromColor) ? targetColor : pixels[x];
        }
     // create result bitmap output 
        Bitmap result = Bitmap.createBitmap(width, height, src.getConfig());
        //set pixels
        result.setPixels(pixels, 0, width, 0, 0, width, height);
 
        return result;
    }
}


3. note that:
  • With the help of this,replaceColor() method you can Replace the color of image on image on click,on action_down,on the fly etc.
  • You can cut the required area of image by changing their color into Color.Transparent.
4. conclusion:
  • Some information about Color Replacement.
  • Know how to Replace image bitmap colors from drawables.
5. About the post:
  •  The code seems to explain itself due to comments, and is very easy to understand.
  •  Don’t mind to write a comment whatever you like to ask, to know,to suggest or recommend.
  •  Hope you enjoy it!

6. Source Code:
        you can download the source code here


Cheers,
Hamad Ali Shaikh

Monday, 26 August 2013

Before Water Mark

Water Mark the Image in ImageView

After Water Mark

Water Mark the Image in ImageView

Create new Android Project

Project Name: PlayingwithBitmaps
Build Target: Android 2.3.3   //or greater than that
Application Name: PlayingwithBitmaps
Package Name: com.hamad.playingwithbitmaps
Create Activity: Main
Min SDK: 10 // or greater than that


  1. create main layout:
  • One image view to display the image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000" >

    <ImageView
        android:id="@+id/imViewAndroid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/car" />

</RelativeLayout>

 2. code of main activity:

package com.shaikhhamadali.blogspot.playingwithbitmaps;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.widget.ImageView;

public class Main extends Activity {
 ImageView imViewAndroid;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
  Point p=new Point();
  p.set(180, 1000);
  Bitmap b=waterMark(BitmapFactory.decodeResource(getResources(), R.drawable.car),"Welcome To Hamad's Blog",p,Color.WHITE,90,30,true);
  imViewAndroid.setImageBitmap(b);

 }
 public  Bitmap waterMark(Bitmap src, String watermark, Point location, int color, int alpha, int size, boolean underline) {
  //get source image width and height
  int w = src.getWidth();
  int h = src.getHeight();

  Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
  //create canvas object
  Canvas canvas = new Canvas(result);
  //draw bitmap on canvas
  canvas.drawBitmap(src, 0, 0, null);
  //create paint object
  Paint paint = new Paint();
  //apply color
  paint.setColor(color);
  //set transparency
  paint.setAlpha(alpha);
  //set text size
  paint.setTextSize(size);
  paint.setAntiAlias(true);
  //set should be underlined or not
  paint.setUnderlineText(underline);
  //draw text on given location
  canvas.drawText(watermark, location.x, location.y, paint);

  return result;
 }
}

3. note that:
  • With the help of this,waterMark() method you can Water mark image on image on click,on action_down,on the fly etc.
  4. conclusion:
  • Some information about Paint and WaterMark.
  • Know how to flip image bitmap from drawables.
  5. About the post:
  •  The code seems to explain itself due to comments, and is very easy to understand.
  •  Don’t mind to write a comment whatever you like to ask, to know,to suggest or recommend.
  •  Hope you enjoy it!

6. Source Code:
        you can download the source code here

Cheers,
Hamad Ali Shaikh

Thursday, 22 August 2013

Before Round Cornered

Round Corner the Image in ImageView

Round Corner the Image in ImageView

After Round Cornered

Round Corner the Image in ImageView
Round=30

Round Corner the Image in ImageView
Round=60


Round Corner the Image in ImageView
Round=30

Round Corner the Image in ImageView
Round=60

Create new Android Project
Project Name: PlayingwithBitmaps
Build Target: Android 2.3.3   //or greater than that
Application Name: PlayingwithBitmaps
Package Name: com.hamad.playingwithbitmaps
Create Activity: Main
Min SDK: 10 // or greater than that
  1. create main layout:
  • One image view to display the image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000" >

    <ImageView
        android:id="@+id/imViewAndroid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/car" />

</RelativeLayout>

 2. code of main activity:

package com.shaikhhamadali.blogspot.playingwithbitmaps;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.widget.ImageView;

public class Main extends Activity {
 ImageView imViewAndroid;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
  imViewAndroid.setImageBitmap(roundCornerImage(BitmapFactory.decodeResource(getResources(), R.drawable.car),60));
 }
 public Bitmap roundCornerImage(Bitmap src, float round) {
  // Source image size
  int width = src.getWidth();
  int height = src.getHeight();
  // create result bitmap output
  Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
  // set canvas for painting
  Canvas canvas = new Canvas(result);
  canvas.drawARGB(0, 0, 0, 0);

  // configure paint
  final Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setColor(Color.BLACK);

  // configure rectangle for embedding
  final Rect rect = new Rect(0, 0, width, height);
  final RectF rectF = new RectF(rect);

  // draw Round rectangle to canvas
  canvas.drawRoundRect(rectF, round, round, paint);

  // create Xfer mode
  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  // draw source image to canvas
  canvas.drawBitmap(src, rect, rect, paint);

  // return final image
  return result;
 }
}

  3. note that:
  • With the help of this,roundCornerImage() method you can Create an image with round corners on your need.
  • The logic behind this is, apply a black rounded corner rectangle to the image for this effect
  4. conclusion:
  • Some information about Rect and RectF method for round corners.
  • Know how to round corner the image bitmap from drawables.
  5. About the post:
  •  The code seems to explain itself due to comments, and is very easy to understand.
  •  Don’t mind to write a comment whatever you like to ask, to know,to suggest or recommend.
  •  Hope you enjoy it!

6. Source Code:
        you can download the source code here

Cheers,
Hamad Ali Shaikh

Wednesday, 21 August 2013

Before Flipping

Image Flipping (Mirroring) in ImageView

After Flipping

Image Flipping (Mirroring) in ImageView
flipped horizontal in mobile

Image Flipping (Mirroring) in ImageView
Horizontal Flip
Create new Android Project
Project Name: PlayingwithBitmaps
Build Target: Android 2.3.3   //or greater than that
Application Name: PlayingwithBitmaps
Package Name: com.hamad.playingwithbitmaps
Create Activity: Main
Min SDK: 10 // or greater than that


  1. create main layout:
  • One image view to display the image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000" >

    <ImageView
        android:id="@+id/imViewAndroid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/car" />

</RelativeLayout>

 2. code of main activity:

package com.shaikhhamadali.blogspot.playingwithbitmaps;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.widget.ImageView;

public class Main extends Activity {
 ImageView imViewAndroid;
 public static final int FLIP_VERTICAL = 1;
 public static final int FLIP_HORIZONTAL = 2;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
  imViewAndroid.setImageBitmap(flipImage(BitmapFactory.decodeResource(getResources(), R.drawable.car),2));
 }
 public Bitmap flipImage(Bitmap src, int type) {
  // create new matrix for transformation
  Matrix matrix = new Matrix();
  // if vertical
  if(type == FLIP_VERTICAL) {
   // y = y * -1
   matrix.preScale(1.0f, -1.0f);
  }
  // if horizonal
  else if(type == FLIP_HORIZONTAL) {
   // x = x * -1
   matrix.preScale(-1.0f, 1.0f);
   // unknown type
  } else {
   return null;
  }

  // return transformed image
  return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
 }
}

3. note that:
  • With the help of this,flipImage() method you can flip image on image on click,on action_down,on etc.
  • This technique is basically same as rotation, however, it transforms rotation with a reverse direction.
    - For vertical flipping: [ x = x, y = y * -1 ]
    - For horizontal flipping: [ x = x * -1, y = y ]
4. conclusion:
  • Some information about Matrix and Image Flipping.
  • Know how to flip image bitmap from drawables.
5. About the post:
  •  The code seems to explain itself due to comments, and is very easy to understand.
  •  Don’t mind to write a comment whatever you like to ask, to know,to suggest or recommend.
  •  Hope you enjoy it!

6. Source Code:
        you can download the source code here

Cheers,
Hamad Ali Shaikh

Tuesday, 20 August 2013

Before Rotation

Image Rotation in ImageView

After Rotation


Image Rotation in ImageView
180 Degree

Image Rotation in ImageView
270 Degree
Create new Android Project

Project Name: PlayingwithBitmaps
Build Target: Android 2.3.3   //or greater than that
Application Name: PlayingwithBitmaps
Package Name: com.hamad.playingwithbitmaps
Create Activity: Main
Min SDK: 10 // or greater than that
  1. create main layout:
  • One image view to display the image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:id="@+id/rlMain" >

    <ImageView
        android:id="@+id/imViewAndroid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/car" />

</RelativeLayout>

 2. code of main activity:

package com.shaikhhamadali.blogspot.playingwithbitmaps;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.widget.ImageView;

public class Main extends Activity {
    ImageView imViewAndroid;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
        imViewAndroid.setImageBitmap(rotateImage(BitmapFactory.decodeResource(getResources(), R.drawable.beautiful),270));
 }
 public Bitmap rotateImage(Bitmap src, float degree) {
     // create new matrix object
     Matrix matrix = new Matrix();
     // setup rotation degree
     matrix.postRotate(degree);
     // return new bitmap rotated using matrix
     return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
 }
}

   3. note that:

  • With the help of this,rotateImage() method you can rotate image on image on click,on action_down,on etc.

  4. conclusion:
  • Some information about Matrix and Image Rotaion.
  • Know how to rotate image bitmap from drawables.
  5. About the post:
  •  The code seems to explain itself due to comments, and is very easy to understand.
  •  Don’t mind to write a comment whatever you like to ask, to know,to suggest or recommend.
  •  Hope you enjoy it!

6. Source Code:
        you can download the source code here

Cheers,
Hamad Ali Shaikh

Friday, 16 August 2013

Before Snow Falling Effect

Snow Falling Effect

After Snow Falling Effect


Snow Falling Effect

Create new Android Project
Project Name: PlayingwithBitmaps
Build Target: Android 2.3.3   //or greater than that
Application Name: PlayingwithBitmaps
Package Name: com.hamad.playingwithbitmaps
Create Activity: Main
Min SDK: 10 // or greater than that


  1. create main layout:


  • One image view to display the image.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:id="@+id/rlMain" >

    <ImageView
        android:id="@+id/imViewAndroid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/car" />

</RelativeLayout>

 2. code of main activity:

package com.shaikhhamadali.blogspot.playingwithbitmaps;

import java.util.Random;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.widget.ImageView;

public class Main extends Activity {
 ImageView imViewAndroid;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
  imViewAndroid.setImageBitmap(applySnowFallingEffect(BitmapFactory.decodeResource(getResources(), R.drawable.beautiful)));
 }
 public Bitmap applySnowFallingEffect(Bitmap source) {
  // get source 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);
  // create 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 RGB colors
    R = Color.red(pixels[index]);
    G = Color.green(pixels[index]);
    B = Color.blue(pixels[index]);
    // generate threshold
    thresHold = random.nextInt(255);
    if(R > thresHold && G > thresHold && B > thresHold) {
     pixels[index] = Color.rgb(255, 255,255);
    }                           
   }
  }
  // create output bitmap                
  Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
  bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
  return bmOut;
 }
}

  3. note that:
  • With the help of this,applySnowFallingEffect() method you can apply Snow Falling Filter Effect on image on click,on action_down etc.
  • also the algorithm is to generate a threshold number (0-255), if all R,G,B values of a pixel are greater than the threshold, then set the pixel to white.
  4. conclusion:
  • Some deep information about Snow Falling Filter effect .
  • Know how to apply Snow Falling Filter Effect on image bitmap from drawables.
  5. About the post:
  • By Using the Approach of Randomizing Image pixel, another filter is created,named White/Snow Falling filter.
  •  The code seems to explain itself due to comments, and is very easy to understand.
  •  Don’t mind to write a comment whatever you like to ask, to know,to suggest or recommend.
  •  Hope you enjoy it!

6. Source Code:
        you can download the source code here


Cheers,
Hamad Ali Shaikh

Before Dark Effect

Round Corner the Image in ImageView

Round Corner the Image in ImageView

After Dark Effect



Create new Android Project

Project Name: PlayingwithBitmaps
Build Target: Android 2.3.3   //or greater than that
Application Name: PlayingwithBitmaps
Package Name: com.hamad.playingwithbitmaps
Create Activity: Main
Min SDK: 10 // or greater than that

  1. create main layout:
  • One image view to display the image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:id="@+id/rlMain" >

    <ImageView
        android:id="@+id/imViewAndroid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/car" />

</RelativeLayout>
 2. code of main activity:

package com.shaikhhamadali.blogspot.playingwithbitmaps;

import java.util.Random;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.widget.ImageView;

public class Main extends Activity {
    ImageView imViewAndroid;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
        imViewAndroid.setImageBitmap(applyDarkFilter(BitmapFactory.decodeResource(getResources(), R.drawable.beautiful)));
 }
 public Bitmap applyDarkFilter(Bitmap source) {
     // get image source 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);
     // create random object
     Random random = new Random();
  
     int R, G, B, index = 0, thresHold = 0;
     // 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 RGB colors
             R = Color.red(pixels[index]);
             G = Color.green(pixels[index]);
             B = Color.blue(pixels[index]);
             // generate threshold
             thresHold = random.nextInt(255);
             if(R < thresHold && G < thresHold && B < thresHold) {
                 pixels[index] = Color.rgb(0,0,0);
             }
         }
     }
     // create output bitmap
     Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
     bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
     return bmOut;
 }
}

  3. note that:
  • With the help of this,applyDarkFilter() method you can apply Dark Filter Effect on image on click,on action_down etc.
  • Basically, the algorithm is to generate a threshold number (0-255), if all R,G,B values of a pixel are less than the threshold, then set the pixel to black.
  4. conclusion:
  • Some deep information about Dark Filter effect .
  • Know how to apply Dark Filter Effect on image bitmap from drawables.
  5. About the post:
  • By Using the Approach of Randomizing Image pixel, another filter is created,named Dark/Black filter,or enhance the noise of darkness
  • this could also used as ink dropping effect.
  •  The code seems to explain itself due to comments, and is very easy to understand.
  •  Don’t mind to write a comment whatever you like to ask, to know,to suggest or recommend.
  •  Hope you enjoy it!

6. Source Code:
        you can download the source code here

Cheers,
Hamad Ali Shaikh

Thursday, 15 August 2013

Before Tint Color Effect

Round Corner the Image in ImageView

Round Corner the Image in ImageView


After Tint Color Effect

Tint Degree=30

Tint Degree=30



Tint Degree=50
Tint Degree=80



Create new Android Project
Project Name: PlayingwithBitmaps
Build Target: Android 2.3.3   //or greater than that
Application Name: PlayingwithBitmaps
Package Name: com.hamad.playingwithbitmaps
Create Activity: Main
Min SDK: 10 // or greater than that


  1. create main layout:


  • One image view to display the image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:id="@+id/rlMain" >

    <ImageView
        android:id="@+id/imViewAndroid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/car" />

</RelativeLayout>
 2. code of main activity:

package com.shaikhhamadali.blogspot.playingwithbitmaps;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;

public class Main extends Activity {
    ImageView imViewAndroid;
    public static final double PI = 3.14159d;
 public static final double FULL_CIRCLE_DEGREE = 360d;
 public static final double HALF_CIRCLE_DEGREE = 180d;
 public static final double RANGE = 256d;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
        imViewAndroid.setImageBitmap(applyTintEffect(BitmapFactory.decodeResource(getResources(), R.drawable.car),80));
 }
  public Bitmap applyTintEffect(Bitmap src, int degree) {
      // get source image size
         int width = src.getWidth();
         int height = src.getHeight();
  
         int[] pix = new int[width * height];
      // get pixel array from source
         src.getPixels(pix, 0, width, 0, 0, width, height);
  
         int RY, GY, BY, RYY, GYY, BYY, R, G, B, Y;
         double angle = (PI * (double)degree) / HALF_CIRCLE_DEGREE;
         
         int S = (int)(RANGE * Math.sin(angle));
         int C = (int)(RANGE * Math.cos(angle));
  
         for (int y = 0; y < height; y++)
             for (int x = 0; x < width; x++) {
                 int index = y * width + x;
                 int r = ( pix[index] >> 16 ) & 0xff;
                 int g = ( pix[index] >> 8 ) & 0xff;
                 int b = pix[index] & 0xff;
                 RY = ( 70 * r - 59 * g - 11 * b ) / 100;
                 GY = (-30 * r + 41 * g - 11 * b ) / 100;
                 BY = (-30 * r - 59 * g + 89 * b ) / 100;
                 Y  = ( 30 * r + 59 * g + 11 * b ) / 100;
                 RYY = ( S * BY + C * RY ) / 256;
                 BYY = ( C * BY - S * RY ) / 256;
                 GYY = (-51 * RYY - 19 * BYY ) / 100;
                 R = Y + RYY;
                 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 );
                 pix[index] = 0xff000000 | (R << 16) | (G << 8 ) | B;
             }
      // output bitmap
         Bitmap outBitmap = Bitmap.createBitmap(width, height, src.getConfig());    
         outBitmap.setPixels(pix, 0, width, 0, 0, width, height);
         
         pix = null;
         
         return outBitmap;
     }
}

  3. note that:
  • With the help of this,applyTintEffect() method you can apply Tint Color Effect on image on click,on action_down etc.
  4. conclusion:
  • Some deep information about Tint Color effect .
  • Know how to apply Tint Color Effect on image bitmap from drawables.
  5. About the post:
  •  The code seems to explain itself due to comments, and is very easy to understand.
  •  I Think this Rocking algorithm,what do you think?
  •  Don’t mind to write a comment whatever you like to ask, to know,to suggest or recommend.
  •  Hope you enjoy it!

6. Source Code:
        you can download the source code here

Cheers,
Hamad Ali Shaikh