Before Emboss 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
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:background="#000000" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/imViewAndroid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/sharpness_high" /> </RelativeLayout>
2. code of main activity:
package com.hamad.playingwithbitmaps; import android.os.Bundle; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BlurMaskFilter; import android.graphics.PorterDuff; import android.graphics.BlurMaskFilter.Blur; import android.graphics.Canvas; 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); imViewAndroid.setImageBitmap(doEmboss(BitmapFactory.decodeResource(getResources(), R.drawable.sharpness_high))); } public Bitmap doEmboss(Bitmap src) { // set Emboss configuration double[][] EmbossConfig = new double[][] { { -1 , 0, -1 }, { 0 , 4, 0 }, { -1 , 0, -1 } }; //create convolution matrix instance ConvolutionMatrix convMatrix = new ConvolutionMatrix(3); //apply configuration convMatrix.applyConfig(EmbossConfig); // set weight of factor and offset convMatrix.Factor = 1; convMatrix.Offset = 127; return ConvolutionMatrix.computeConvolution3x3(src, convMatrix); } }
3. note that:
- For better understanding please refer to my previous post:convolution matrix
- With the help of this,doEmboss() method you can apply Emboss Effect on image on click,on action_down etc.
- Some deep information about Emboss effect .
- Know how to apply Emboss effect on image bitmap from drawables.
5. about the post:
[ -1 | 0 | -1 ][ 0 | 4 | 0 ][ -1 | 0 | -1 ]The factor is 1 and offset is 127.
- 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