How the Android program changes the original color of the image in the code

Source: Internet
Author: User

Recently, while looking for a job to improve the previous project. Before the Android Junior level project is imitating the cool dog music player. Download an apk file, change the suffix, unzip it, and then follow the layout of the official app to get the picture done. Remember the cool dog home There are several main icons, extracted after the white plus transparent combination, but the official application is to change the theme color will follow the changes, this time just empty on the internet to find ways to follow the change.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5B/ED/wKiom1UWeoaS5atqAAAX_KaqAH0239.jpg "style=" float: none; "title=" D1.png "alt=" Wkiom1uweoas5atqaaax_kaqah0239.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5B/E7/wKioL1UWe76QnQFIAAADFXp3WwM288.jpg "style=" float: none; "title=" D11.png "alt=" Wkiol1uwe76qnqfiaaadfxp3wwm288.jpg "/>

It's easy to change white to another color.

Package com.example.ex_tupian;import android.app.activity;import android.graphics.bitmap;import  android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color; import android.graphics.colormatrix;import android.graphics.colormatrixcolorfilter;import  android.graphics.matrix;import android.graphics.paint;import android.os.bundle;import  android.view.menu;import android.view.view;import android.view.view.onclicklistener;import  android.widget.imageview;public class mainactivity extends activity {private  imageview ma; private bitmap bitmap, updatebitmap;      private canvas canvas;      private paint paint;        @Overrideprotected  void oncreate (bundle savedinstancestate)  { Super.oncreate (savedinstancestate); setconteNtview (R.layout.activity_main);ma =  (ImageView)  findviewbyid (r.id.imageview00); bitmap =  bitmapfactory.decoderesource (Getresources (),  R.DRAWABLE.D1);           updatebitmap = bitmap.createbitmap (Bitmap.getwidth (),                   bitmap.getheight (),  bitmap.getconfig ());           canvas = new  canvas (UPDATEBITMAP);           paint = new  paint (Paint.anti_alias_flag);//anti-aliasing brush           final  colormatrix cm = new colormatrix ();           paint.setcolorfilter (New colormatrixcolorfilter (cm));           paint.setColor (Color.Black);           paint.setantialias (True);           final Matrix matrix = new  Matrix ();           canvas.drawbitmap (Bitmap, matrix,  paint);           ma.setimagebitmap (UPDATEBITMAP);   findviewbyid (R.id.button1). Setonclicklistener (New onclicklistener ()  {@Overridepublic  void onclick (VIEW V)  {// todo auto-generated method stubcm.set (new  float[] { 160 / 128f, 0, 0, 0, 0,//  Red Value                             0, 32 / 128f, 0, 0, 0,//  Green Value          &nbSp;                 0,  0, 240 / 128f, 0, 0,//  Blue Value                            0,  0, 0, 1, 0 //  Transparency                    });                   paint.setcolorfilter (New colormatrixcolorfilter (CM) );                   Canvas.drawbitmap (Bitmap, matrix, paint);                   ma.setimagebitmap (updatebitmap);   }});}}

That's the main thing. Setting the color

New float[] { 160/128f, 0, 0, 0, 0,//red values

0, 32/128f, 0, 0, 0,//Green value

0, 0, 240/128f, 0, 0,//blue value

0, 0, 0, 1, 0//transparency

}

This is set up is purple, this is just very simple conversion, can achieve the effect, if you need more content, you can refer to these URLs or search by themselves.

http://blog.csdn.net/loongggdroid/article/details/18708911

Http://www.cnblogs.com/leon19870907/articles/1978065.html

Then one is because usually directly with the 8-bit hexadecimal set color, this need RGB, so refer to this URL

http://blog.csdn.net/yanzi1225627/article/details/8581270


This article is from the "Fly to learn Android" blog, please be sure to keep this source http://qq445493481.blog.51cto.com/9545543/1626006

How the Android program changes the original color of the image in the code

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.