title: How to convert Grayscale IplImage to Bitmap in JavaCV for Android?
body: <p>I am working on a Android app which will get a <code>Bitmap</code> from <code>ImageView</code>. Convert this <code>Bitmap</code> to JavaCV<code>IplImage</code> and then to grayscale as below:</p>
  
  <pre><code>IplImage image = IplImage.create(width, height, IPL_DEPTH_8U, 4);
  bitmap.copyPixelsToBuffer(image.getByteBuffer());
  IplImage _3image = IplImage.create(width, height, IPL_DEPTH_8U, 3);
  IplImage _1image = IplImage.create(width, height, IPL_DEPTH_8U, 1);
  cvCvtColor(image, _3image, CV_BGRA2BGR);
  cvCvtColor(_3image, _1image, CV_RGB2GRAY);
  </code></pre>
  
  <p>However I get a <code>RuntimeException: Buffer not large enough for pixels</code> when I do this </p>
  
  <pre><code>Bitmap x = Bitmap.createBitmap(width, height, Config.ARGB_8888);            
  x.copyPixelsFromBuffer(_1image.getByteBuffer());
  </code></pre>
  
  <p>Any help would be appreciated. Thank you.</p>