3

Here i attach code that convert Bitmap to Byte array now i have to regenerate bitmap to show in android Image-view.

In below code mRawBitmapData is byte Araay. Here code is create byte array for converted image so now i have to regenerate the bitmap from this byte array.

private void convertArgbToGrayscale(Bitmap bmpOriginal, int width, int height){
    int pixel;
    int k = 0;
    int B=0,G=0,R=0;
    try{
        for(int x = 0; x < height; x++) {
            for(int y = 0; y < width; y++, k++) {

                pixel = bmpOriginal.getPixel(y, x);

                if(pixel == -1){
                    mDataArray[k] = 1;
                }
                else {
                    mDataArray[k] = 0;
                }
            }
            if(mDataWidth>width){
                for(int p=width;p<mDataWidth;p++,k++){
                    mDataArray[k]=0;
                }
            }
        }
    }catch (Exception e) {

        Log.e(TAG, e.toString());
    }
}

private void createRawMonochromeData(){
    int length = 0;
    for (int i = 0; i < mDataArray.length; i = i + 8) {

        int k=0;
        for (int j = 7; j >=0; j--, k++) {
            if(mDataArray[i+k]==1)
            {
                mRawBitmapData[length] |= 1 << j;
            }
            else
            {
                mRawBitmapData[length] &= ~(1 << j);
            }

        }

        length++;

    }
}

2 Answers 2

12
byte[] bitmapdata; // let this be your byte array
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);
Sign up to request clarification or add additional context in comments.

Comments

3

Use BitmapFactory of Android for getting bitmap from byte array like :

Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata.length);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.