/*** 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