如何在JavaCV for Android中将Grayscale IplImage转换为Bitmap?

时间:2013-03-11 11:19:54

标签: android bitmap javacv grayscale

我正在开发一款Android应用,它将从Bitmap获得ImageView。将此Bitmap转换为JavaCV IplImage,然后转换为灰度,如下所示:

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);

但是当我这样做时,我得到RuntimeException: Buffer not large enough for pixels

Bitmap x = Bitmap.createBitmap(width, height, Config.ARGB_8888);            
x.copyPixelsFromBuffer(_1image.getByteBuffer());

任何帮助将不胜感激。谢谢。

0 个答案:

没有答案