Android Basics Getting Started tutorial--8.3.10 Paint API--colorfilter (color filter) (2-3)

Source: Internet
Author: User
Tags gettext mul

Android Basics Getting Started tutorial--8.3.10 Paint API--colorfilter (color filter) (2-3)

tags (space delimited): Uncategorized

Introduction to this section:

In the previous section we explained the first subclass of the colorfilter(color filter) in the paint API in android:
Colormatrixcolorfilter (Color matrix color filter), I believe that we also broaden the view of Android image processing,
In this section, we'll look at its second subclass:lightingcolorfilter(light color filter), first
Official API Documentation: Lightingcolorfilter, there are not many things in the document, the key here:

The idea is that a color filter can be used to simulate a simple lighting effect, with two parameters for the construction method, one
Used to multiply the original image of the RPG value, one added to the previous results! In fact, the calculation method is nothing:
(RGB value * mul + Add)% 255, thus getting the new RPG value, here the percent is the remainder, in addition, the whole process of alpha does not
Participate in change! Let's write an example to verify the validation!

1. code example:

Run :

Implementation Code :

First, a simple layout:activity_main.xml:

<relativelayout xmlns:android="Http://schemas.android.com/apk/res/android"xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="Match_parent"android:layout_height="Match_parent"android:padding="5DP"tools:context=". Mainactivity "> <imageview android:ID="@+id/img_meizi"Android:layout_width="300DP"android:layout_height="300DP"Android:src="@mipmap/img_meizi"/> <edittext android:ID="@+id/edit_mul"Android:layout_width="Wrap_content"android:layout_height="Wrap_content"android:layout_below="@id/img_meizi"Android:text="0"/> <edittext android:ID="@+id/edit_add"Android:layout_width="Wrap_content"android:layout_height="Wrap_content"android:layout_below="@id/edit_mul"Android:text="0"/> <button android:ID="@+id/btn_change"Android:layout_width="Wrap_content"android:layout_height="Wrap_content"android:layout_alignright="@id/img_meizi"android:layout_below="@id/img_meizi"Android:text="Change"/></relativelayout>

Then there's our Mainactiivty.java, which is also very simple:

 Public  class mainactivity extends appcompatactivity  implements  View. Onclicklistener {    PrivateImageView Img_meizi;PrivateEditText Edit_mul;PrivateEditText Edit_add;PrivateButton Btn_change;PrivateBitmap Mbitmap;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        Mbitmap = Bitmapfactory.decoderesource (Getresources (), R.mipmap.img_meizi);    Bindviews (); }Private void bindviews() {Img_meizi = (ImageView) Findviewbyid (R.id.img_meizi);        Edit_mul = (EditText) Findviewbyid (R.id.edit_mul);        Edit_add = (EditText) Findviewbyid (R.id.edit_add);        Btn_change = (Button) Findviewbyid (R.id.btn_change); Btn_change.setonclicklistener ( This); }PrivateBitmapProcessimage(Bitmap BP,intMulintAdd) {Bitmap Bitmap = Bitmap.createbitmap (Bp.getwidth (), Bp.getheight (), Bitmap.Config.ARGB_8888); Canvas Canvas =NewCanvas (bitmap); Paint paint =NewPaint (Paint.anti_alias_flag); Paint.setcolorfilter (NewLightingcolorfilter (Mul,add)); Canvas.drawbitmap (BP,0,0, paint);returnBitmap }@Override     Public void OnClick(View v) {Switch(V.getid ()) { CaseR.id.btn_change:intMul = Integer.parseint (Edit_mul.gettext (). toString ());intAdd = Integer.parseint (Edit_add.gettext (). toString ()); Img_meizi.setimagebitmap (Processimage (Mbitmap,mul,add)); Break; }    }}

All right, Lightingcolorfilter's demo is complete ~

3. Download the code in this section

Lightingcolorfilterdemo.zip

This section summarizes:

Well, this section demonstrates a basic use of lightingcolorfilter to simulate simple lighting effects,
To achieve a simple picture processing effect, OK, this section is here, thank you ~

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Basics Getting Started tutorial--8.3.10 Paint API--colorfilter (color filter) (2-3)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.