I am trying to convert a JPEG that is in a bitmap to a mat. I know that the Utils method only supports images in RGB888 format so I take force my camera to be in JPEG format, take the picture, decode it and the convert it to RGB 888 format and then call the utils method to get a mat from it. Here is the basic code:
Bitmap imageBitmap = BitmapFactory.decodeByteArray(mData, 0, mData.length);
double scale = 0.5; // Make the image smaller incase I was running out of memeory.
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, (int) (imageBitmap.getWidth() * scale),
(int) (imageBitmap.getHeight() * scale), false);
imageBitmap = PNGtoRGB888(imageBitmap);
Mat m = Utils.bitmapToMat(imageBitmap); // I get a runtime exception
Here is the PNGtoRGB888 method:
private Bitmap PNGtoRGB888(Bitmap _img)
{
int numPixels = _img.getWidth() * _img.getHeight();
int[] pixels = new int[numPixels];
// Get Bitmap's pixels. Each int is the color values for one pixel.
_img.getPixels(pixels, 0, _img.getWidth(), 0, 0, _img.getWidth(), _img.getHeight());
// Create a Bitmap of the appropriate format.
Bitmap result = Bitmap.createBitmap(_img.getWidth(), _img.getHeight(), Config.ARGB_8888);
// Set RGB pixels.
result.setPixels(pixels, 0, result.getWidth(), 0, 0, result.getWidth(), result.getHeight());
return result;
}
Any ideas why I would get the runtime exception?!?!?!?
I had to reorganize my build path and it worked.