Before Smooth 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
- 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/beautiful" />
</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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imViewAndroid = (ImageView) findViewById(R.id.imViewAndroid);
imViewAndroid.setImageBitmap(applySmoothEffect(BitmapFactory.decodeResource(getResources(), R.drawable.beautiful),5));
}
public Bitmap applySmoothEffect(Bitmap src, double value) {
//create convolution matrix instance
ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
convMatrix.setAll(1);
convMatrix.Matrix[1][1] = value;
// set weight of factor and offset
convMatrix.Factor = value + 8;
convMatrix.Offset = 1;
return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
}}
3. note that:
- For better understanding please refer to my previous post:convolution matrix
- With the help of this,applySmoothEffect() method you can apply Smooth Effect on image on click,on action_down etc.
- Some deep information about Smooth effect .
- Know how to apply Smooth effect on image bitmap from drawables.
5. About the post:
The applied matrix for the effect:[ 1 | 1 | 1 ][ 1 | 5 | 1 ][ 1 | 1 | 1 ]The factor is 13 and offset 1.
- 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,
you can download the source code here
Hamad Ali Shaikh

