jloyd / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Impossible to show gray image in Bitmap #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi:

  I cannot show an image transofrmed to gray scale in a bitmap that is attached to an ImageView.

  This is may code:

        Bitmap sourceARGB = BitmapFactory.decodeResource( this.getResources(),R.drawable.images);

        int w = sourceARGB.getWidth();
        int h = sourceARGB.getHeight();

        try
        {

           IplImage image = IplImage.create( w, h, IPL_DEPTH_8U, 4);
           sourceARGB.copyPixelsToBuffer( image.getByteBuffer() );
           IplImage grayImage = IplImage.create( w, h, IPL_DEPTH_8U, 1);

           cvCvtColor(image, grayImage, CV_BGR2GRAY);
           Bitmap target = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
           target.copyPixelsFromBuffer(grayImage.getByteBuffer());
           ((ImageView) this.findViewById( R.id.target )).setImageBitmap( target );

           cvReleaseImage(image);
           cvReleaseImage(grayImage);

        }catch (Exception e) 
        {
           Log.e("ERROR", "ERROR in Code: " + e.toString());                    
           e.printStackTrace();
        }    

Im always getting 

 "java.lang.RuntimeException: Buffer not large enough for pixels"

Using lattest JavaCV with Android 2.2

Thanks in advance

Original issue reported on code.google.com by drrom...@gmail.com on 24 Jun 2011 at 10:11

GoogleCodeExporter commented 9 years ago
The error is throw in line 
target.copyPixelsFromBuffer(grayImage.getByteBuffer());

Original comment by drrom...@gmail.com on 24 Jun 2011 at 10:12

GoogleCodeExporter commented 9 years ago
Bitmap target = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
target.copyPixelsFromBuffer(grayImage.getByteBuffer());

target is bigger than grayImage, so that error is perfectly normal... Anything 
else to report or can we close this issue?

Original comment by samuel.a...@gmail.com on 24 Jun 2011 at 10:18

GoogleCodeExporter commented 9 years ago
Ok. Sorry for the error. You can close

Original comment by drrom...@gmail.com on 27 Jun 2011 at 6:00

GoogleCodeExporter commented 9 years ago
Ok, but about making Bitmap <-> IplImage interaction easier, you can refer to 
issue #67 for any future progress in this direction

Original comment by samuel.a...@gmail.com on 29 Jun 2011 at 4:06