我需要在 Android 位图中转换 1 channel iplimage(灰色)。我有:
IplImage aux = IplImage.create(senal_gray.width, senal_gray.height, IPL_DEPTH_8U, 4);
cvCvtColor(senal_gray, aux, CV_GRAY2BGRA);
Bitmap bm = Bitmap.createBitmap(aux.width, aux.height, Bitmap.Config.ARGB_8888);
bm.copyPixelsFromBuffer(aux.getByteBuffer());
最佳答案
我从未使用过适用于 Android 的 OpenCV 绑定(bind),但这里有一些代码可以帮助您入门。将其视为伪代码,因为我无法尝试...但您会了解基本概念。
public static Bitmap IplImageToBitmap(IplImage src) {
int width = src.width;
int height = src.height;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
for(int r=0;r<height;r++) {
for(int c=0;c<width;c++) {
int gray = (int) Math.floor(cvGet2D(src,r,c).getVal(0));
bitmap.setPixel(c, r, Color.argb(255, gray, gray, gray));
}
}
return bitmap;
}
关于android - 1 channel iplimage -> Android 位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8807414/