Android Pictures Bitmap Special handling

Source: Internet
Author: User

Recently doing a functional development: a special effect occurs when the finger touches the screen. Here need to be colorful pictures to achieve a brilliant effect, today I say how to use a simple picture (1) to achieve (2) effect!


(Fig. 1)


(Fig. 2)


From the above (Figure 1) You can know that the image is actually no color, in fact, white and transparency to draw the four round piece! How to achieve the right picture of the colorful round image it! Here is the design to the bitmap image processing! Here's how to change the color of a bitmap picture:

public static Bitmap Change_bitmap_for_curr_color (Bitmap curr_bitmap, int new_color) {if (null = = Curr_bitmap) {return Curr_bitmap;} int Black_color = 0xff000000;int start_x = 0;int statr_y = 0;int Bitmap_w = Curr_bitmap.getwidth (); int bitmap_h = Curr_Bit Map.getheight ();//LOG.D ("Yu", "Fingermagic_tool change_bitmap_for_curr_color new_color=" +new_color);// 0xffff0000new_color &= 0x00ffffff;/x Remove the transparency to change the color, here just change the color of the picture, its transparency does not change x///log.d ("Fingermagic_tool", "fingermagic _tool change_bitmap_for_curr_color new_color= "+new_color); int []pixels = new int[bitmap_w * Bitmap_h]; Curr_bitmap.getpixels (pixels, 0, bitmap_w, 0, 0, bitmap_w,bitmap_h);/x Here's the pixel data to change Bitmap X/int = Alph 0;int = 0;int Curr_index = 0;for (int i = 0; i < Bitmap_h; i++) {/x here is the change of the extracted bitnap pixel data, is its color is the color we want to change x/for (int j = 0; J < Bi Tmap_w; J + +) {Curr_index = Bitmap_w * i + j;color_int = pixels[curr_index];if (0 = = Color_int) {/x if the pixel has no color, full transparency does not handle x/continue;}  Alph = Color_int & Black_color; /x takes out the transparency value of the pixel point x/if(Alph = = 0) {/x If this pixel is fully transparent then do not process x/continue;} Color_int = New_color |                alph;/x the color we need plus the transparency of the pixel to replace the original pixel x/pixels[curr_index] = color_int;}} <pre name= "code" class= "Java" >/x finally uses the pixel data values we have modified to create the image we need x/Bitmap result = Bitmap.createbitmap ( Pixels, Bitmap_w, bitmap_h, config.argb_8888);//result.setpixels (pixels, 0, bitmap_w, 0, 0, Bitmap_w, bitmap_h); return Result;}


That's it! All the key points, I have added comments.

However, for the above code is still defective, please do not use to deal with oversized bitmap, it is possible overflow oh! Also, if you deal with more than one small picture, please open a thread to deal with OH.


Android Pictures Bitmap Special handling

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.