Tuesday 6 December 2011

Apply Color to ImageView (PNG) file {foreground color}in Andriod.....

For apply color to an image in andriod....i search lot of blogs and different websites.only solution for apply background color. but thier is no solution for apply foreground color.. .but i try and find the solution for that...
Here below code is  apply color to image.. Foreground color..apply .

Main.xml(GUI)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 <Button android:text="Apply Color to Png image "
  android:layout_height="wrap_content"
  android:id="@+id/select"
  android:layout_width="fill_parent">
  </Button>
 <ImageView android:src="@drawable/icon"
 android:layout_height="wrap_content"
 android:id="@+id/imageView1"
 android:layout_width="wrap_content"
 ></ImageView>

</LinearLayout>







Activity class:
 public class ImageColorexample extends Activity {
    /** Called when the activity is first created. */
      ImageView image;
     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
  image=(ImageView)findViewById(R.id.imageView1);
      Button b=(Button)findViewById(R.id.select);
         b.setOnClickListener(new OnClickListener()          
            @Override
            public void onClick(View v) {

//code to apply foregroundcolor to png image...
            image.setColorFilter(Color.rgb(123,73,122),
                          android.graphics.PorterDuff.Mode.MULTIPLY );

       
            }
        });
    }
}


Screen short:
Before applying color



When user click on Button..Foreground color will be apply to image...






These below methods are use full to apply color ..






No comments:

Post a Comment

Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of...