How to convert bitmap byte nude data into bitmap picture int data in Android

Source: Internet
Author: User
Tags bmp image

How to convert bitmap byte nude data to bitmap images in Android int data 2014-06-11 10:45:14 read 375 times

We processed the BMP image raw data in jni, how should we convert it to bitmap?

Because the resulting data is unsigned char * type data, and for bitmap class, its class method inside:

12 publicstatic Bitmap createBitmap(int colors[], int offset, int stride,            int width, intheight, Config config)

Required to pass in int * data, here we need to convert unsigned char * data to an int value of RGB.

The Java method can take the following code:

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 publicstaticintconvertByteToInt(bytedata){                int heightBit = (int) ((data>>4) & 0x0F);        intlowBit = (int) (0x0F& data);        returnheightBit * 16+ lowBit;    }        publicstaticint[] convertByteToColor(byte[] data){        intsize = data.length;        if(size == 0){            returnnull;        }                intarg = 0;        if(size % 3!= 0){            arg = 1;        }                int[]color = newint[size / 3+ arg];        intred, green, blue;                if(arg == 0){            for(int i = 0; i < color.length; ++i){                red = convertByteToInt(data[i * 3]);                green = convertByteToInt(data[i * 31]);                blue = convertByteToInt(data[i * 32]);                                                   color[i] = (red << 16) | (green << 8) | blue | 0xFF000000;              }        }else{            for(inti = 0; i < color.length - 1; ++i){                red = convertByteToInt(data[i * 3]);                green = convertByteToInt(data[i * 3 1]);                blue = convertByteToInt(data[i * 32]);                   color[i] = (red << 16) | (green << 8) | blue | 0xFF000000;              }                        color[color.length - 1] = 0xFF000000;        }            returncolor;    }    Bitmap decodeFrameToBitmap(byte[] frame)     {        int[]colors = convertByteToColor(frame);        if(colors == null){            returnnull;        }        Bitmap bmp = Bitmap.createBitmap(colors, 012801280720,Bitmap.Config.ARGB_8888);                               return bmp;    }

The code does not explain, has the question blog to mention, will answer.

-end-

How to convert bitmap byte nude data into bitmap picture int data in Android

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.