我正在创建一个人脸检测应用程序并减少我正在使用后台线程的主线程上的工作量。代码如下。
Thread background = new Thread(new Runnable() {
public void run() {
Log.d ("Thread", "Thread has started");
for (Feature feat : mClassifierFiles.keySet()) {
mFaces.put(feat, cvHaarDetectObjects(grayImage, mClassifiers.get(feat), mStorages.get(feat), 1.1, 3,
CV_HAAR_DO_CANNY_PRUNING));
if (mFaces.get(feat).total() > 0) {
Size previewSize = camera.getParameters().getPreviewSize();
YuvImage yuvimage=new YuvImage(data, ImageFormat.NV21, previewSize.width, previewSize.height, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
yuvimage.compressToJpeg(new Rect(0, 0, previewSize.width, previewSize.height), 100, baos);
byte[] jdata = baos.toByteArray();
Bitmap bmp = BitmapFactory.decodeByteArray(jdata, 0, jdata.length);
saveImg(bmp);
}
postInvalidate();
opencv_core.cvClearMemStorage(mStorages.get(feat));
}
}
});
background.start ();
现在,我知道保存图像部分应该在主线程中完成。现在我不明白的是,如何将“位图 bmp”发送到主线程?