Log in or register to post comments

How to transform camera image to android.graphics.Bitmap

November 10, 2015 - 11:24pm #1
Hi,
I want to transform camera image to android.graphics.Bitmap. The following is my source code, but the imageview object named m_ivCamera can not show the bitmap correctly.
Thank you very much.


@Override
public void onQCARUpdate(State state) {  
    Image imageRGB565 = null;
    Frame frame = state.getFrame();
          
    for (int i = 0; i < frame.getNumImages(); ++i) {
        Image image = frame.getImage(i);
        if (image.getFormat() == PIXEL_FORMAT.RGB565) {
            imageRGB565 = image;
            break;
        }
    }
          
    if (imageRGB565 != null) {
        ByteBuffer pixels = imageRGB565.getPixels();
        byte[] pixelArray = new byte[pixels.remaining()];
        pixels.get(pixelArray, 0, pixelArray.length());
        int imageWidth = imageRGB565.getWidth();
        int imageHeight = imageRGB565.getHeight();
        int stride = imageRGB565.getStride();
        
        Options opts = new BitmapFactory.Options();
        opts.inPreferredConfig = Bitmap.Config.RGB_656;
        Bitmap bm = BitmapFactory.decodeByByteArray(pixelArray, 0, pixelArray.length, opts);

        // m_ivCamera is a android.widget.ImageView object.
        m_ivCamera.setImageBitmap(bm);
    }

 

 

How to transform camera image to android.graphics.Bitmap

August 29, 2019 - 12:45pm #4

I'm having same problem as you @sanjaytestid.

I added Vuforia.setFrameFormat(PIXEL_FORMAT.RGB565, true); in startAR() as mentioned in the documentation but I'm still getting GRAYSCALE image from frames. 

On top of that, I couldn't create bitmap image as well. Please let me know if you have any solution. 

How to transform camera image to android.graphics.Bitmap

February 4, 2019 - 4:29am #3

I tried this solution but i getting PIXEL_FORMAT.GRAYSCALE not PIXEL_FORMAT.RGB565. If I initialize imageRGB565 for GRAYSCALE than BitmapFactory.decodeByByteArray(pixelArray, 0, pixelArray.length, opts); return null.

 

How to transform camera image to android.graphics.Bitmap

December 3, 2015 - 11:57am #2

Looks like you have a few typos in your code:

opts.inPreferredConfig = Bitmap.Config.RGB_656;
Bitmap bm = BitmapFactory.decodeByByteArray(pixelArray, 0, pixelArray.length, opts);

http://developer.android.com/reference/android/graphics/BitmapFactory.html

http://developer.android.com/reference/android/graphics/Bitmap.Config.html

 

Log in or register to post comments