Message info
To:Android Developers From:adiel ashrov Subject:[android-developers] Troubles with Utils.matToBitmap Date:Sun, 19 Feb 2012 08:18:05 -0800 (PST)

Hey everyone,

I have s small app which takes a picture and i want to threshold it.
for some reason the function Utils.matToBitmap crashes when I use it
after the threshold, any thoughts on how to solve this?

the Code:
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
try {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
this._Gray = Utils.bitmapToMat(bitmap);
Mat tMat = thresholdPicture();
Bitmap tOutBitmap =
if (Utils.matToBitmap(tMat, tOutBitmap))//Crash here
Drawable drawable =new BitmapDrawable(getResources(),tOutBitmap);
SurfaceView tSurfaceView = (SurfaceView)
tSurfaceView.setBackgroundDrawable(drawable);//TODO: not
working if we picture vertically
Log.i("OpenCV", "Failed convert mat to bitmap");
catch (Exception e) {
Log.i("OpenCV", "Failed to Use OpenCV" + e.getMessage());

private Mat thresholdPicture(){
Mat tMatThreshed = new Mat();
Imgproc.cvtColor(this._Gray, this._Gray, Imgproc.COLOR_RGB2GRAY);
Imgproc.threshold(this._Gray, tMatThreshed, 100,
return tMatThreshed;



Thank you

You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at