Android - Image Effects Tutorial

<p >Android allows you to manipulate images by adding different kinds of effects on the images. You can easily apply image processing techniques to add certain kinds of effects on images. The effects could be brightness,darkness, grayscale conversion e.t.c.</p> <p >Android provides Bitmap class to handle images. This can be found under android.graphics.bitmap. There are many ways through which you can instantiate bitmap. We are creating a bitmap of image from the imageView.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="kwd" >private</span><span class="pln" > </span><span class="typ" >Bitmap</span><span class="pln" > bmp</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >private</span><span class="pln" > </span><span class="typ" >ImageView</span><span class="pln" > img</span><span class="pun" >;</span><span class="pln" > img </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >ImageView</span><span class="pun" >)</span><span class="pln" >findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >imageView1</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >BitmapDrawable</span><span class="pln" > abmp </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >BitmapDrawable</span><span class="pun" >)</span><span class="pln" >img</span><span class="pun" >.</span><span class="pln" >getDrawable</span><span class="pun" >();</span></pre> <p >Now we will create bitmap by calling getBitmap() function of BitmapDrawable class. Its syntax is given below &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pln" >bmp </span><span class="pun" >=</span><span class="pln" > abmp</span><span class="pun" >.</span><span class="pln" >getBitmap</span><span class="pun" >();</span></pre> <p >An image is nothing but a two dimensional matrix. Same way you will handle a bitmap. An image consist of pixels. So you will get pixels from this bitmap and apply processing to it. Its syntax is as follows &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > i</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > i</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >();</span><span class="pln" > i</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > j</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > j</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >();</span><span class="pln" > j</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > p </span><span class="pun" >=</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span></pre> <p >The getWidth() and getHeight() functions returns the height and width of the matrix. The getPixel() method returns the pixel at the specified index. Once you got the pixel, you can easily manipulate it according to your needs.</p> <p >Apart from these methods, there are other methods that helps us manipulate images more better.</p> <table class="table table-bordered" > <tbody > <tr > <th >Sr.No</th> <th >Method &amp; description</th> </tr> <tr > <td >1</td> <td ><b >copy(Bitmap.Config config, boolean isMutable)</b> <p >This method copy this bitmap&#39;s pixels into the new bitmap</p> </td> </tr> <tr > <td >2</td> <td ><b >createBitmap(DisplayMetrics display, int width, int height, Bitmap.Config config)</b> <p >Returns a mutable bitmap with the specified width and height</p> </td> </tr> <tr > <td >3</td> <td ><b >createBitmap(int width, int height, Bitmap.Config config)</b> <p >Returns a mutable bitmap with the specified width and height</p> </td> </tr> <tr > <td >4</td> <td ><b >createBitmap(Bitmap src)</b> <p >Returns an immutable bitmap from the source bitmap</p> </td> </tr> <tr > <td >5</td> <td ><b >extractAlpha()</b> <p >Returns a new bitmap that captures the alpha values of the original</p> </td> </tr> <tr > <td >6</td> <td ><b >getConfig()</b> <p >This mehtod eturn that config, otherwise return null</p> </td> </tr> <tr > <td >7</td> <td ><b >getDensity()</b> <p >Returns the density for this bitmap</p> </td> </tr> <tr > <td >8</td> <td ><b >getRowBytes()</b> <p >Return the number of bytes between rows in the bitmap&#39;s pixels</p> </td> </tr> <tr > <td >9</td> <td ><b >setPixel(int x, int y, int color)</b> <p >Write the specified Color into the bitmap (assuming it is mutable) at the x,y coordinate</p> </td> </tr> <tr > <td >10</td> <td ><b >setDensity(int density)</b> <p >This method specifies the density for this bitmap</p> </td> </tr> </tbody> </table> <h2 >Example</h2> <p >The below example demonstrates some of the image effects on the bitmap. It crates a basic application that allows you to convert the picture into grayscale and much more.</p> <p >To experiment with this example , you need to run this on an actual device.</p> <table class="table table-bordered" > <tbody > <tr > <th >Steps</th> <th >Description</th> </tr> <tr > <td >1</td> <td >You will use Android studio to create an Android application under a package com.example.sairamkrishna.myapplication. While creating this project, make sure you Target SDK and Compile With at the latest version of Android SDK to use higher levels of APIs.</td> </tr> <tr > <td >2</td> <td >Modify src/MainActivity.java file to add necessary code.</td> </tr> <tr > <td >3</td> <td >Modify the res/layout/activity_main to add respective XML components</td> </tr> <tr > <td >4</td> <td >Run the application and choose a running android device and install the application on it and verify the results</td> </tr> </tbody> </table> <p >Following is the content of the modified<b >MainActivity.java</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="kwd" >package</span><span class="pln" > com</span><span class="pun" >.</span><span class="pln" >example</span><span class="pun" >.</span><span class="pln" >sairamkrishna</span><span class="pun" >.</span><span class="pln" >myapplication</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >graphics</span><span class="pun" >.</span><span class="typ" >Bitmap</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >graphics</span><span class="pun" >.</span><span class="typ" >Color</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >graphics</span><span class="pun" >.</span><span class="pln" >drawable</span><span class="pun" >.</span><span class="typ" >BitmapDrawable</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >support</span><span class="pun" >.</span><span class="pln" >v7</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >ActionBarActivity</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >os</span><span class="pun" >.</span><span class="typ" >Bundle</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >View</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >Button</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >ImageView</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >class</span><span class="pln" > </span><span class="typ" >MainActivity</span><span class="pln" > </span><span class="kwd" >extends</span><span class="pln" > </span><span class="typ" >ActionBarActivity</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="typ" >Button</span><span class="pln" > b1</span><span class="pun" >,</span><span class="pln" > b2</span><span class="pun" >,</span><span class="pln" > b3</span><span class="pun" >;</span><span class="pln" > </span><span class="typ" >ImageView</span><span class="pln" > im</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >private</span><span class="pln" > </span><span class="typ" >Bitmap</span><span class="pln" > bmp</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >private</span><span class="pln" > </span><span class="typ" >Bitmap</span><span class="pln" > operation</span><span class="pun" >;</span><span class="pln" > </span><span class="lit" >@Override</span><span class="pln" > </span><span class="kwd" >protected</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onCreate</span><span class="pun" >(</span><span class="typ" >Bundle</span><span class="pln" > savedInstanceState</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >super</span><span class="pun" >.</span><span class="pln" >onCreate</span><span class="pun" >(</span><span class="pln" >savedInstanceState</span><span class="pun" >);</span><span class="pln" > setContentView</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >layout</span><span class="pun" >.</span><span class="pln" >activity_main</span><span class="pun" >);</span><span class="pln" > b1 </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >Button</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >button</span><span class="pun" >);</span><span class="pln" > b2 </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >Button</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >button2</span><span class="pun" >);</span><span class="pln" > b3 </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >Button</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >button3</span><span class="pun" >);</span><span class="pln" > im </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >ImageView</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >imageView</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >BitmapDrawable</span><span class="pln" > abmp </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >BitmapDrawable</span><span class="pun" >)</span><span class="pln" > im</span><span class="pun" >.</span><span class="pln" >getDrawable</span><span class="pun" >();</span><span class="pln" > bmp </span><span class="pun" >=</span><span class="pln" > abmp</span><span class="pun" >.</span><span class="pln" >getBitmap</span><span class="pun" >();</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > gray</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > view</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > operation </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Bitmap</span><span class="pun" >.</span><span class="pln" >createBitmap</span><span class="pun" >(</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >(),</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >(),</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getConfig</span><span class="pun" >());</span><span class="pln" > </span><span class="kwd" >double</span><span class="pln" > red </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0.33</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >double</span><span class="pln" > green </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0.59</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >double</span><span class="pln" > blue </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0.11</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >for</span><span class="pln" > </span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > i </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > i </span><span class="pun" >&lt;</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >();</span><span class="pln" > i</span><span class="pun" >++)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >for</span><span class="pln" > </span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > j </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > j </span><span class="pun" >&lt;</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >();</span><span class="pln" > j</span><span class="pun" >++)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > p </span><span class="pun" >=</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >red</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >green</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >blue</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="kwd" >int</span><span class="pun" >)</span><span class="pln" > red </span><span class="pun" >*</span><span class="pln" > r</span><span class="pun" >;</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="kwd" >int</span><span class="pun" >)</span><span class="pln" > green </span><span class="pun" >*</span><span class="pln" > g</span><span class="pun" >;</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="kwd" >int</span><span class="pun" >)</span><span class="pln" > blue </span><span class="pun" >*</span><span class="pln" > b</span><span class="pun" >;</span><span class="pln" > operation</span><span class="pun" >.</span><span class="pln" >setPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >argb</span><span class="pun" >(</span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >),</span><span class="pln" > r</span><span class="pun" >,</span><span class="pln" > g</span><span class="pun" >,</span><span class="pln" > b</span><span class="pun" >));</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > im</span><span class="pun" >.</span><span class="pln" >setImageBitmap</span><span class="pun" >(</span><span class="pln" >operation</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > bright</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > view</span><span class="pun" >){</span><span class="pln" > operation</span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Bitmap</span><span class="pun" >.</span><span class="pln" >createBitmap</span><span class="pun" >(</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >(),</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >(),</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getConfig</span><span class="pun" >());</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > i</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > i</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >();</span><span class="pln" > i</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > j</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > j</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >();</span><span class="pln" > j</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > p </span><span class="pun" >=</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >red</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >green</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >blue</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >100</span><span class="pln" > </span><span class="pun" >+</span><span class="pln" > r</span><span class="pun" >;</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >100</span><span class="pln" > </span><span class="pun" >+</span><span class="pln" > g</span><span class="pun" >;</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >100</span><span class="pln" > </span><span class="pun" >+</span><span class="pln" > b</span><span class="pun" >;</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >100</span><span class="pln" > </span><span class="pun" >+</span><span class="pln" > alpha</span><span class="pun" >;</span><span class="pln" > operation</span><span class="pun" >.</span><span class="pln" >setPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >argb</span><span class="pun" >(</span><span class="pln" >alpha</span><span class="pun" >,</span><span class="pln" > r</span><span class="pun" >,</span><span class="pln" > g</span><span class="pun" >,</span><span class="pln" > b</span><span class="pun" >));</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > im</span><span class="pun" >.</span><span class="pln" >setImageBitmap</span><span class="pun" >(</span><span class="pln" >operation</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > dark</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > view</span><span class="pun" >){</span><span class="pln" > operation</span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Bitmap</span><span class="pun" >.</span><span class="pln" >createBitmap</span><span class="pun" >(</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >(),</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >(),</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getConfig</span><span class="pun" >());</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > i</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > i</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >();</span><span class="pln" > i</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > j</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > j</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >();</span><span class="pln" > j</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > p </span><span class="pun" >=</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >red</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >green</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >blue</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > r </span><span class="pun" >-</span><span class="pln" > </span><span class="lit" >50</span><span class="pun" >;</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > g </span><span class="pun" >-</span><span class="pln" > </span><span class="lit" >50</span><span class="pun" >;</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > b </span><span class="pun" >-</span><span class="pln" > </span><span class="lit" >50</span><span class="pun" >;</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > alpha </span><span class="pun" >-</span><span class="lit" >50</span><span class="pun" >;</span><span class="pln" > operation</span><span class="pun" >.</span><span class="pln" >setPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >argb</span><span class="pun" >(</span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >),</span><span class="pln" > r</span><span class="pun" >,</span><span class="pln" > g</span><span class="pun" >,</span><span class="pln" > b</span><span class="pun" >));</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > im</span><span class="pun" >.</span><span class="pln" >setImageBitmap</span><span class="pun" >(</span><span class="pln" >operation</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > gama</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > view</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > operation </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Bitmap</span><span class="pun" >.</span><span class="pln" >createBitmap</span><span class="pun" >(</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >(),</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >(),</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getConfig</span><span class="pun" >());</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > i</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > i</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >();</span><span class="pln" > i</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > j</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > j</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >();</span><span class="pln" > j</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > p </span><span class="pun" >=</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >red</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >green</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >blue</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > r </span><span class="pun" >+</span><span class="pln" > </span><span class="lit" >150</span><span class="pun" >;</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > operation</span><span class="pun" >.</span><span class="pln" >setPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >argb</span><span class="pun" >(</span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >),</span><span class="pln" > r</span><span class="pun" >,</span><span class="pln" > g</span><span class="pun" >,</span><span class="pln" > b</span><span class="pun" >));</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > im</span><span class="pun" >.</span><span class="pln" >setImageBitmap</span><span class="pun" >(</span><span class="pln" >operation</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > green</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > view</span><span class="pun" >){</span><span class="pln" > operation </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Bitmap</span><span class="pun" >.</span><span class="pln" >createBitmap</span><span class="pun" >(</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >(),</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >(),</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getConfig</span><span class="pun" >());</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > i</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > </span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >();</span><span class="pln" > i</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > j</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > j</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >();</span><span class="pln" > j</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > p </span><span class="pun" >=</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >red</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >green</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >blue</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > g</span><span class="pun" >+</span><span class="lit" >150</span><span class="pun" >;</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > operation</span><span class="pun" >.</span><span class="pln" >setPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >argb</span><span class="pun" >(</span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >),</span><span class="pln" > r</span><span class="pun" >,</span><span class="pln" > g</span><span class="pun" >,</span><span class="pln" > b</span><span class="pun" >));</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > im</span><span class="pun" >.</span><span class="pln" >setImageBitmap</span><span class="pun" >(</span><span class="pln" >operation</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > blue</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > view</span><span class="pun" >){</span><span class="pln" > operation </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Bitmap</span><span class="pun" >.</span><span class="pln" >createBitmap</span><span class="pun" >(</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >(),</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >(),</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getConfig</span><span class="pun" >());</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > i</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > i</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getWidth</span><span class="pun" >();</span><span class="pln" > i</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > j</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > j</span><span class="pun" >&lt;</span><span class="pln" >bmp</span><span class="pun" >.</span><span class="pln" >getHeight</span><span class="pun" >();</span><span class="pln" > j</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > p </span><span class="pun" >=</span><span class="pln" > bmp</span><span class="pun" >.</span><span class="pln" >getPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >red</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >green</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >blue</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >);</span><span class="pln" > r </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > g </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > b </span><span class="pun" >=</span><span class="pln" > b</span><span class="pun" >+</span><span class="lit" >150</span><span class="pun" >;</span><span class="pln" > alpha </span><span class="pun" >=</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > operation</span><span class="pun" >.</span><span class="pln" >setPixel</span><span class="pun" >(</span><span class="pln" >i</span><span class="pun" >,</span><span class="pln" > j</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >argb</span><span class="pun" >(</span><span class="typ" >Color</span><span class="pun" >.</span><span class="pln" >alpha</span><span class="pun" >(</span><span class="pln" >p</span><span class="pun" >),</span><span class="pln" > r</span><span class="pun" >,</span><span class="pln" > g</span><span class="pun" >,</span><span class="pln" > b</span><span class="pun" >));</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > im</span><span class="pun" >.</span><span class="pln" >setImageBitmap</span><span class="pun" >(</span><span class="pln" >operation</span><span class="pun" >);</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span></pre> <p >Following is the modified content of the xml<b >res/layout/activity_main.xml</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="tag" >&lt;RelativeLayout</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >xmlns:tools</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/tools&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:paddingLeft</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingRight</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingTop</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingBottom</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >tools:context</span><span class="pun" >=</span><span class="atv" >&quot;.MainActivity&quot;</span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentTop</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >&quot;30dp&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Image Effects&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Tutorials Point&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >&quot;35dp&quot;</span><span class="pln" > </span><span class="atn" >android:textColor</span><span class="pun" >=</span><span class="atv" >&quot;#ff16ff01&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;ImageView</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/imageView&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:src</span><span class="pun" >=</span><span class="atv" >&quot;@drawable/logo&quot;</span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Gray&quot;</span><span class="pln" > </span><span class="atn" >android:onClick</span><span class="pun" >=</span><span class="atv" >&quot;gray&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentBottom</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentLeft</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentStart</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_marginBottom</span><span class="pun" >=</span><span class="atv" >&quot;97dp&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;dark&quot;</span><span class="pln" > </span><span class="atn" >android:onClick</span><span class="pun" >=</span><span class="atv" >&quot;dark&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignBottom</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentRight</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentEnd</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Bright&quot;</span><span class="pln" > </span><span class="atn" >android:onClick</span><span class="pun" >=</span><span class="atv" >&quot;bright&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button3&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignTop</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Red&quot;</span><span class="pln" > </span><span class="atn" >android:onClick</span><span class="pun" >=</span><span class="atv" >&quot;gama&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button4&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button3&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentLeft</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignParentStart</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Green&quot;</span><span class="pln" > </span><span class="atn" >android:onClick</span><span class="pun" >=</span><span class="atv" >&quot;green&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button5&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignTop</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button4&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignLeft</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button3&quot;</span><span class="pln" > </span><span class="atn" >android:layout_alignStart</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button3&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;blue&quot;</span><span class="pln" > </span><span class="atn" >android:onClick</span><span class="pun" >=</span><span class="atv" >&quot;blue&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button6&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button2&quot;</span><span class="pln" > </span><span class="atn" >android:layout_toRightOf</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView&quot;</span><span class="pln" > </span><span class="atn" >android:layout_toEndOf</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/RelativeLayout&gt;</span></pre> <p >Following is the content of<b >AndroidManifest.xml</b>file.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;manifest</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >package</span><span class="pun" >=</span><span class="atv" >&quot;com.example.sairamkrishna.myapplication&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;application</span><span class="pln" > </span><span class="atn" >android:allowBackup</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:icon</span><span class="pun" >=</span><span class="atv" >&quot;@mipmap/ic_launcher&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;@string/app_name&quot;</span><span class="pln" > </span><span class="atn" >android:theme</span><span class="pun" >=</span><span class="atv" >&quot;@style/AppTheme&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;activity</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;.MainActivity&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;@string/app_name&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;action</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.intent.action.MAIN&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;category</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.intent.category.LAUNCHER&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;/activity&gt;</span><span class="pln" > </span><span class="tag" >&lt;/application&gt;</span><span class="pln" > </span><span class="tag" >&lt;/manifest&gt;</span></pre> <p >Let&#39;s try to run our application we just modified. I assume you had created your<b >AVD</b>while doing environment setup. To run the app from Android studio, open one of your project&#39;s activity files and click Run<img alt="Eclipse Run Icon" class="inline" src="http://www.tutorialspoint.com/android/images/eclipse_run.jpg" />icon from the toolbar. Android studio installs the app on your AVD and starts it and if everything is fine with your setup and application, it will display following Emulator window &minus;</p> <p><img alt="Anroid Image Effects Tutorial" src="http://www.tutorialspoint.com/android/images/effects.jpg" /></p> <p >Now if you will look at your device screen , you will see the an image of android along with three buttons.</p> <p >Now just select the Gray button that will convert your image into grayscale and will update the UI. It is shown below &minus;</p> <p><img alt="Anroid Image Effects Tutorial" src="http://www.tutorialspoint.com/android/images/effects1.jpg" /></p> <p >Now tap on the bright button, that will add some value to each pixel of the image and thus makes an illusion of brightness. It is shown below &minus;</p> <p><img alt="Anroid Image Effects Tutorial" src="http://www.tutorialspoint.com/android/images/effects2.jpg" /></p> <p >Now tap on the dark button, that will subtract some value to each pixel of the image and thus makes an illusion of dark. It is shown below &minus;</p> <p><img alt="Anroid Image Effects Tutorial" src="http://www.tutorialspoint.com/android/images/effects3.jpg" /></p> <p >Now tap on the red button, that will subtract some value to each pixel of the image and thus makes an illusion of dark. It is shown below &minus;</p> <p><img alt="Anroid Image Effects Tutorial" src="http://www.tutorialspoint.com/android/images/effects4.jpg" /></p> <p >Now tap on the green button, that will subtract some value to each pixel of the image and thus makes an illusion of dark. It is shown below &minus;</p> <p><img alt="Anroid Image Effects Tutorial" src="http://www.tutorialspoint.com/android/images/effects5.jpg" /></p> <p >Now tap on the blue button, that will subtract some value to each pixel of the image and thus makes an illusion of dark. It is shown below &minus;</p> <p><img alt="Anroid Image Effects Tutorial" src="http://www.tutorialspoint.com/android/images/effects6.jpg" /></p> <div></div>
RangeTime:0.006975s
RangeMem:267.54 KB
返回顶部 留言