Android Development replaces color values in bitmap

Source: Internet
Author: User

/*** Replace a color value in the bitmap with a new color *@paramBitmap *@paramOldcolor *@paramNewcolor *@return     */     Public StaticBitmap Replacebitmapcolor (Bitmap oldbitmap,intOldcolor,intNewcolor) {        //For instructions, refer tohttp://xys289187120.blog.51cto.com/3361352/657590/Bitmap Mbitmap = oldbitmap.copy (config.argb_8888,true); //loop to get bitmap all pixel points        intMbitmapwidth =mbitmap.getwidth (); intMbitmapheight =mbitmap.getheight (); intMarraycolorlengh = Mbitmapwidth *Mbitmapheight; int[] Marraycolor =New int[Marraycolorlengh]; intCount = 0;  for(inti = 0; i < mbitmapheight; i++) {                       for(intj = 0; J < Mbitmapwidth; J + +) {                              //gets the color value of each point in the bitmap picture//The color value that will be populated if it is not//here's a note. If color is fully transparent or full black returns a value of 0//getPixel () without transparent channel getPixel32 () with transparent part so full transparency is 0x00000000//and the opaque black is 0xff000000, and if you don't calculate the transparent part, it's 0.                intcolor =Mbitmap.getpixel (J, I); //the color value exists in an array for easy later modification                if(color = =Oldcolor)  {Mbitmap.setpixel (J, I, Newcolor); //Replace white with a transparent color                    }                                                  }          }        returnMbitmap; }

How to use:

Iv_image.setimagebitmap (Bitmaputil.replacebitmapcolor (Gifdecoder.getframe (i), Color.White, Color.TRANSPARENT));

Android Development replaces color values in bitmap

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.