May 16, 2012

Sharpen image, using Convolution Matrix

Example to sharpen image, on Android using Convolution Matrix.

Sharpen image, using Convolution Matrix


Copy text picture in /res/drawable/ folder, name it testpicture.jpg.

package com.AndroidImageProcessing;

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

public class AndroidImageProcessingActivity extends Activity {
 
 final static int KERNAL_WIDTH = 3;
 final static int KERNAL_HEIGHT = 3;
 
 int[][] kernalBlur ={
   {0, -1, 0},
   {-1, 5, -1},
   {0, -1, 0}
 };
 
 ImageView imageSource, imageAfter;
 Bitmap bitmap_Source;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imageSource = (ImageView)findViewById(R.id.imageSource);
        imageAfter = (ImageView)findViewById(R.id.imageAfter);
        
        bitmap_Source = BitmapFactory.decodeResource(getResources(), R.drawable.testpicture);
        
        Bitmap afterSharpen = processingBitmap(bitmap_Source, kernalBlur);
        imageAfter.setImageBitmap(afterSharpen);
    }
    
    private Bitmap processingBitmap(Bitmap src, int[][] knl){
     Bitmap dest = Bitmap.createBitmap(
       src.getWidth(), src.getHeight(), src.getConfig());
     
     int bmWidth = src.getWidth();
     int bmHeight = src.getHeight();
     int bmWidth_MINUS_2 = bmWidth - 2;
     int bmHeight_MINUS_2 = bmHeight - 2;
     
     for(int i = 1; i <= bmWidth_MINUS_2; i++){
      for(int j = 1; j <= bmHeight_MINUS_2; j++){
       
       //get the surround 3*3 pixel of current src[i][j] into a matrix subSrc[][]
       int[][] subSrc = new int[KERNAL_WIDTH][KERNAL_HEIGHT];
       for(int k = 0; k < KERNAL_WIDTH; k++){
        for(int l = 0; l < KERNAL_HEIGHT; l++){
         subSrc[k][l] = src.getPixel(i-1+k, j-1+l);
        }
       }
       
       //subSum = subSrc[][] * knl[][]
       int subSumA = 0;
       int subSumR = 0;
       int subSumG = 0;
       int subSumB = 0;

       for(int k = 0; k < KERNAL_WIDTH; k++){
        for(int l = 0; l < KERNAL_HEIGHT; l++){
         subSumA += Color.alpha(subSrc[k][l]) * knl[k][l];
         subSumR += Color.red(subSrc[k][l]) * knl[k][l];
         subSumG += Color.green(subSrc[k][l]) * knl[k][l];
         subSumB += Color.blue(subSrc[k][l]) * knl[k][l];
        }
       }
       
       if(subSumA<0){
        subSumA = 0;
       }else if(subSumA>255){
        subSumA = 255;
       }
       
       if(subSumR<0){
        subSumR = 0;
       }else if(subSumR>255){
        subSumR = 255;
       }
       
       if(subSumG<0){
        subSumG = 0;
       }else if(subSumG>255){
        subSumG = 255;
       }
       
       if(subSumB<0){
        subSumB = 0;
       }else if(subSumB>255){
        subSumB = 255;
       }

       dest.setPixel(i, j, Color.argb(
         subSumA, 
         subSumR, 
         subSumG, 
         subSumB));
      } 
     }
     
     return dest;
    }

}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout 
            android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="vertical" >
         <TextView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="Original" />
      <ImageView
          android:id="@+id/imageSource" 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:src="@drawable/testpicture"/>
      <TextView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="Result" />
      <ImageView
          android:id="@+id/imageAfter" 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
      
     </LinearLayout>
    </ScrollView>

</LinearLayout>


Related:
- Image processing on Android, the basic logic of Convolution Matrix.
- Apply Blur effect on Android, using Convolution Matrix
- Process image in background thread


May 15, 2012

Apply Blur effect on Android, using Convolution Matrix


Last article describe the basic logic of Convolution Matrix, it's used to apply Blur effect on Bitmap.

Apply Blur effect on Android, using Convolution Matrix


- The Kernal used for blur is:
{1, 1, 1
  1, 1, 1
  1, 1, 1}

- There are 9 '1' in the Kernal, so we have to divid the sum of each pixel by 9, to make it in the save level.

- Each color is limited within the range of 0~255.

- To make the blur effect more obviously, the processingBitmap of blur is called 5 times.

package com.AndroidImageProcessing;

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

public class AndroidImageProcessingActivity extends Activity {
 
 final static int KERNAL_WIDTH = 3;
 final static int KERNAL_HEIGHT = 3;
 
 int[][] kernalBlur ={
   {1, 1, 1},
   {1, 1, 1},
   {1, 1, 1}
 };
 
 int DIV_BY_9 = 9;
 
 ImageView imageSource, imageAfter;
 Bitmap bitmap_Source;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imageSource = (ImageView)findViewById(R.id.imageSource);
        imageAfter = (ImageView)findViewById(R.id.imageAfter);
        
        bitmap_Source = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        
        Bitmap afterBlur = processingBitmap(bitmap_Source, kernalBlur);
        afterBlur = processingBitmap(afterBlur, kernalBlur);
        afterBlur = processingBitmap(afterBlur, kernalBlur);
        afterBlur = processingBitmap(afterBlur, kernalBlur);
        afterBlur = processingBitmap(afterBlur, kernalBlur);
        imageAfter.setImageBitmap(afterBlur);
    }
    
    private Bitmap processingBitmap(Bitmap src, int[][] knl){
     Bitmap dest = Bitmap.createBitmap(
       src.getWidth(), src.getHeight(), src.getConfig());
     
     int bmWidth = src.getWidth();
     int bmHeight = src.getHeight();
     int bmWidth_MINUS_2 = bmWidth - 2;
     int bmHeight_MINUS_2 = bmHeight - 2;
     
     for(int i = 1; i <= bmWidth_MINUS_2; i++){
      for(int j = 1; j <= bmHeight_MINUS_2; j++){
       
       //get the surround 3*3 pixel of current src[i][j] into a matrix subSrc[][]
       int[][] subSrc = new int[KERNAL_WIDTH][KERNAL_HEIGHT];
       for(int k = 0; k < KERNAL_WIDTH; k++){
        for(int l = 0; l < KERNAL_HEIGHT; l++){
         subSrc[k][l] = src.getPixel(i-1+k, j-1+l);
        }
       }
       
       //subSum = subSrc[][] * knl[][]
       int subSumA = 0;
       int subSumR = 0;
       int subSumG = 0;
       int subSumB = 0;

       for(int k = 0; k < KERNAL_WIDTH; k++){
        for(int l = 0; l < KERNAL_HEIGHT; l++){
         subSumA += Color.alpha(subSrc[k][l]) * knl[k][l];
         subSumR += Color.red(subSrc[k][l]) * knl[k][l];
         subSumG += Color.green(subSrc[k][l]) * knl[k][l];
         subSumB += Color.blue(subSrc[k][l]) * knl[k][l];
        }
       }
       
       subSumA = subSumA/DIV_BY_9;
       subSumR = subSumR/DIV_BY_9;
       subSumG = subSumG/DIV_BY_9;
       subSumB = subSumB/DIV_BY_9;
       
       if(subSumA<0){
        subSumA = 0;
       }else if(subSumA>255){
        subSumA = 255;
       }
       
       if(subSumR<0){
        subSumR = 0;
       }else if(subSumR>255){
        subSumR = 255;
       }
       
       if(subSumG<0){
        subSumG = 0;
       }else if(subSumG>255){
        subSumG = 255;
       }
       
       if(subSumB<0){
        subSumB = 0;
       }else if(subSumB>255){
        subSumB = 255;
       }

       dest.setPixel(i, j, Color.argb(
         subSumA, 
         subSumR, 
         subSumG, 
         subSumB));
      } 
     }
     
     return dest;
    }

}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout 
            android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="vertical" >
         <TextView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="Original" />
      <ImageView
          android:id="@+id/imageSource" 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:src="@drawable/ic_launcher"/>
      <TextView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="Result" />
      <ImageView
          android:id="@+id/imageAfter" 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
      
     </LinearLayout>
    </ScrollView>

</LinearLayout>


Related:
- Sharpen image, using Convolution Matrix


May 13, 2012

Image processing on Android, the basic logic of Convolution Matrix.


At the beginning when I prepare the post "Create blur edge on bitmap, using BlurMaskFilter", I want to apply blur effect on bitmap actually. But I can't find any build-in API do so it! In the coming posts, I try to do it myself.

I found a page in http://docs.gimp.org/en/plug-in-convmatrix.html, it explain Convolution Matrix very clear and easy understand. So my first step is to implement the Convolution Matrix according to the example.



package com.AndroidImageProcessing;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidImageProcessingActivity extends Activity {
 
 final static int KERNAL_WIDTH = 3;
 final static int KERNAL_HEIGHT = 3;
 final static int MATRIX_WIDTH = 5;
 final static int MATRIX_HEIGHT = 5;
 
 int[][] kernal ={
   {0, 1, 0},
   {0, 0, 0},
   {0, 0, 0}
 };
 
 int[][] dataOriginal = {
   {35, 40, 41, 45, 50},
   {40, 40, 42, 46, 52},
   {42, 46, 50, 55, 55},
   {48, 52, 56, 58, 60},
   {56, 60, 65, 70, 75}
 };
 
 int[][] dataResult = new int[MATRIX_WIDTH][MATRIX_HEIGHT];
 
 TextView textOriginal, textResult;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textOriginal = (TextView)findViewById(R.id.original);
        textResult = (TextView)findViewById(R.id.result);
        
        dataResult = convolution(dataOriginal, kernal);
        
        textOriginal.setText("dataOriginal:\n" + getDataString(dataOriginal) + "\n");
        textResult.setText("dataResult:\n" + getDataString(dataResult) + "\n");
    }
    
    private String getDataString(int[][] d){
     String s = "";
     
     for(int i = 0; i < d.length; i++){
      for(int j = 0; j < d[i].length; j++){
       s += " " + String.format("%02d", d[i][j]);
      }
      s += "\n"; 
     }
     
     return s;
    }
    
    private int[][] convolution(int[][] src, int[][] knl){
     int[][] convolutionResult = new int[MATRIX_WIDTH][MATRIX_HEIGHT];
     
     for(int i = 1; i <= src.length-2; i++){
      for(int j = 1; j <= src[i].length-2; j++){
       
       //get the surround 3*3 pixel of current src[i][j] into a matrix subSrc[][]
       int[][] subSrc = new int[KERNAL_WIDTH][KERNAL_HEIGHT];
       for(int k = 0; k < subSrc.length; k++){
        for(int l = 0; l < subSrc[k].length; l++){
         subSrc[k][l] = src[i-1+k][j-1+l]; 
        }
       }
       
       //subSum = subSrc[][] * knl[][]
       int subSum = 0;
       for(int k = 0; k < knl.length; k++){
        for(int l = 0; l < knl[k].length; l++){
         subSum += subSrc[k][l] * knl[k][l];
        }
       }

       convolutionResult[i][j] = subSum;
      } 
     }
     
     return convolutionResult;
    }
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <TextView
        android:id="@+id/original"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/result"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>


Next:
- Apply Blur effect on Android, using Convolution Matrix
- Sharpen image, using Convolution Matrix
- Process image in background thread
- Edge Enhance
- Edge Detect
- Gaussian Blur
- Display image in full size
- Unsharp Mask (USM)
- Reduce bitmap by setting inSampleSize of BitmapFactory.Options
- Auto resize bitmap to fit View
- Image Processing with open JPG file dialog
- Inverse bitmap to generate film like picture
- Resize bitmap: Bitmap.createScaledBitmap vs BitmapFactory.Options.inSampleSize



May 11, 2012

Example of EmbossMaskFilter

EmbossMaskFilter(float[] direction, float ambient, float specular, float blurRadius) create an emboss maskfilter.
  • direction: array of 3 scalars [x, y, z] specifying the direction of the light source
  • ambient: 0...1 amount of ambient light
  • specular: coefficient for specular highlights
  • blurRadius: amount to blur before applying lighting

Example of EmbossMaskFilter


package com.AndroidBitmapProcessing;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.EmbossMaskFilter;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class AndroidBitmapProcessingActivity extends Activity {
 
 ImageView imageView_Source, imageAfter;
 Bitmap bitmap_Source, bitmap_Dest;
 
 SeekBar ambientBar, specularBar, blurRadiusBar;
 TextView ambientText, specularText, blurRadiusText;
 Button doProcess;
 
 float ambientValue = 0.5f;
 float specularValue = 5.0f;
 float blurRadiusValue = 5.0f;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imageView_Source = (ImageView)findViewById(R.id.source);
        imageAfter = (ImageView)findViewById(R.id.imageAfter);

        //bitmap_Source = BitmapFactory.decodeResource(getResources(), R.drawable.testpicture);
        bitmap_Source = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        imageAfter.setImageBitmap(processingBitmap_Emboss(bitmap_Source));
        
        ambientBar = (SeekBar)findViewById(R.id.ambientBar);
        specularBar = (SeekBar)findViewById(R.id.specularBar);
        blurRadiusBar = (SeekBar)findViewById(R.id.blurRadiusBar);
     ambientText = (TextView)findViewById(R.id.ambientText);
     specularText = (TextView)findViewById(R.id.specularText);
     blurRadiusText = (TextView)findViewById(R.id.blurRadiusText);
        
        doProcess = (Button)findViewById(R.id.doProcess);
        
        ambientBar.setOnSeekBarChangeListener(ambientBarChangeListener);
        specularBar.setOnSeekBarChangeListener(specularBarChangeListener);
        blurRadiusBar.setOnSeekBarChangeListener(blurRadiusBarChangeListener);
        
        doProcess.setOnClickListener(doProcessClickListener);
        
    }
    
    OnClickListener doProcessClickListener
    = new OnClickListener(){

  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   imageAfter.setImageBitmap(processingBitmap_Emboss(bitmap_Source));
  }};
    
    OnSeekBarChangeListener ambientBarChangeListener
    = new OnSeekBarChangeListener(){

  @Override
  public void onProgressChanged(SeekBar seekBar, int progress,
    boolean fromUser) {
   ambientValue = progress/10f;
   ambientText.setText("ambient: " + String.valueOf(ambientValue));
  }

  @Override
  public void onStartTrackingTouch(SeekBar seekBar) {
   // TODO Auto-generated method stub
   
  }

  @Override
  public void onStopTrackingTouch(SeekBar seekBar) {
   // TODO Auto-generated method stub
   
  }
     
    };
    
    OnSeekBarChangeListener specularBarChangeListener
    = new OnSeekBarChangeListener(){

  @Override
  public void onProgressChanged(SeekBar seekBar, int progress,
    boolean fromUser) {
   // TODO Auto-generated method stub
   specularValue = progress/10f;
   specularText.setText("specular: " + String.valueOf(specularValue));
  }

  @Override
  public void onStartTrackingTouch(SeekBar seekBar) {
   // TODO Auto-generated method stub
   
  }

  @Override
  public void onStopTrackingTouch(SeekBar seekBar) {
   // TODO Auto-generated method stub
   
  }
     
    };
    
    OnSeekBarChangeListener blurRadiusBarChangeListener
    = new OnSeekBarChangeListener(){

  @Override
  public void onProgressChanged(SeekBar seekBar, int progress,
    boolean fromUser) {
   blurRadiusValue = progress/10f;
   blurRadiusText.setText("blurRadius: " + String.valueOf(blurRadiusValue));
   
  }

  @Override
  public void onStartTrackingTouch(SeekBar seekBar) {
   // TODO Auto-generated method stub
   
  }

  @Override
  public void onStopTrackingTouch(SeekBar seekBar) {
   // TODO Auto-generated method stub
   
  }
     
    };
    
    private Bitmap processingBitmap_Emboss(Bitmap src){
     int width = src.getWidth();
        int height = src.getHeight();

        EmbossMaskFilter embossMaskFilter;
        Paint paintEmboss = new Paint();
        
        Bitmap dest = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
     Canvas canvas = new Canvas(dest);

     Bitmap alpha = src.extractAlpha();
          
     embossMaskFilter = new EmbossMaskFilter(
       new float[] { 1, 1, 1 },
       ambientValue, 
       specularValue, 
       blurRadiusValue);
     
     paintEmboss.setMaskFilter(embossMaskFilter);
     canvas.drawBitmap(alpha, 0, 0, paintEmboss);
     
        return dest;
    }
    
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout 
            android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="vertical" >
         <TextView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="Original" />
      <ImageView
          android:id="@+id/source" 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:src="@drawable/ic_launcher"/>
      <TextView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="Result" />
      <ImageView
          android:id="@+id/imageAfter" 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
      
   <SeekBar
       android:id="@+id/ambientBar"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:paddingLeft="10dp"
       android:paddingRight="10dp"
       android:max="10"
       android:progress="5"/>
   <TextView
       android:id="@+id/ambientText"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="ambient: 0.5"/>
   
   <SeekBar
       android:id="@+id/specularBar"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:paddingLeft="10dp"
       android:paddingRight="10dp"
       android:max="100"
       android:progress="50"/>
   <TextView
       android:id="@+id/specularText"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="specular: 5"/>
   
   <SeekBar
       android:id="@+id/blurRadiusBar"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:paddingLeft="10dp"
       android:paddingRight="10dp"
       android:max="100"
       android:progress="50"/>
   <TextView
       android:id="@+id/blurRadiusText"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="blurRadius: 5"/>
   
   <Button
       android:id="@+id/doProcess"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="Do Process"/>
     </LinearLayout>
 </ScrollView>
</LinearLayout>


May 10, 2012

Create blur edge on bitmap, using BlurMaskFilter.

The android.graphics.BlurMaskFilter class takes a mask, and blurs its edge by the specified radius. This example show how to make blur bitmap inner, and blur white outer edge.

Create blur edge on bitmap, using BlurMaskFilter.


package com.AndroidBitmapProcessing;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class AndroidBitmapProcessingActivity extends Activity {
 
 ImageView imageView_Source, imageAfter;
 Bitmap bitmap_Source, bitmap_Dest;
 
 SeekBar blurBar;
 TextView blurText;
 Button doProcess;
 
 int blurValue = 1;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imageView_Source = (ImageView)findViewById(R.id.source);
        imageAfter = (ImageView)findViewById(R.id.imageAfter);

        //bitmap_Source = BitmapFactory.decodeResource(getResources(), R.drawable.testpicture);
        bitmap_Source = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        imageAfter.setImageBitmap(processingBitmap_Blur(bitmap_Source));
        
        blurBar = (SeekBar)findViewById(R.id.blurBar);
        blurText = (TextView)findViewById(R.id.blurText);
        doProcess = (Button)findViewById(R.id.doProcess);
        
        blurBar.setOnSeekBarChangeListener(blurBarChangeListener);
        doProcess.setOnClickListener(doProcessClickListener);
        
    }
    
    OnClickListener doProcessClickListener
    = new OnClickListener(){

  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   imageAfter.setImageBitmap(processingBitmap_Blur(bitmap_Source));
  }};
    
    OnSeekBarChangeListener blurBarChangeListener
    = new OnSeekBarChangeListener(){

  @Override
  public void onProgressChanged(SeekBar seekBar, int progress,
    boolean fromUser) {
   blurValue = progress+1;
   blurText.setText(String.valueOf(blurValue));
  }

  @Override
  public void onStartTrackingTouch(SeekBar seekBar) {
   // TODO Auto-generated method stub
   
  }

  @Override
  public void onStopTrackingTouch(SeekBar seekBar) {
   // TODO Auto-generated method stub
   
  }
     
    };

    private Bitmap processingBitmap_Blur(Bitmap src){
     int width = src.getWidth();
        int height = src.getHeight();
        
     BlurMaskFilter blurMaskFilter;
     Paint paintBlur = new Paint();
     
     Bitmap dest = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
     Canvas canvas = new Canvas(dest); 
     
     //Create background in White
     Bitmap alpha = src.extractAlpha();
     paintBlur.setColor(0xFFFFFFFF);
     canvas.drawBitmap(alpha, 0, 0, paintBlur);
     
     //Create outer blur, in White
     blurMaskFilter = new BlurMaskFilter(blurValue, BlurMaskFilter.Blur.OUTER);
     paintBlur.setMaskFilter(blurMaskFilter);
     canvas.drawBitmap(alpha, 0, 0, paintBlur);
     
     //Create inner blur
     blurMaskFilter = new BlurMaskFilter(blurValue, BlurMaskFilter.Blur.INNER);
     paintBlur.setMaskFilter(blurMaskFilter);
     canvas.drawBitmap(src, 0, 0, paintBlur);
     
     
     
     return dest;
    }

}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout 
            android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="vertical" >
         <TextView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="Original" />
      <ImageView
          android:id="@+id/source" 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:src="@drawable/ic_launcher"/>
      <TextView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="Result" />
      <ImageView
          android:id="@+id/imageAfter" 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
   <SeekBar
       android:id="@+id/blurBar"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:max="99"
       android:progress="0"/>
   <TextView
       android:id="@+id/blurText"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="1"/>
   <Button
       android:id="@+id/doProcess"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="Do Process"/>
     </LinearLayout>
 </ScrollView>
</LinearLayout>


Infolinks In Text Ads