我正在重新发布此问题,因为我不确定之前是否正确提出了这个问题::)我正在开发一个包含面部检测的应用程序。相机启动正常。在预览帧回调中,我实例化一个faceview对象(此类处理检测)。此类只能检测位图中的面孔,但回调中的图像是YuvImage。我已将图像压缩为jpeg,然后调用了将jpeg转换为位图的方法,因此检测将起作用。

我遇到的问题是日食表示我正在使用的YuvImage有一个classnotfoundexception。我已经下载了yuvimage所属的api8。源代码中没有错误,可以正常编译。为什么ecilipse无法加载yuvimage类?这是一个片段,谢谢。

'码'

BitmapFactory.Options bfo = new BitmapFactory.Options();
bfo.inPreferredConfig = Bitmap.Config.RGB_565;
Rect rectangle = new Rect(0, 0, width, height);
ByteArrayOutputStream bos = new ByteArrayOutputStream(imageData.length);
try{
    img = new YuvImage(imageData,ImageFormat.NV21,width,height,null);
}catch(Exception e){
    e.printStackTrace();
}
img.compressToJpeg(rectangle, 100, bos);
byte[] array = bos.toByteArray();


sourceImage = BitmapFactory.decodeByteArray(array, 0, array.length);


异常跟踪:

02-10 11:53:07.298: ERROR/dalvikvm(2364): Could not find class 'android.graphics.YuvImage', referenced from method com.tecmark.FaceView.<init>
02-10 11:53:07.468: ERROR/AndroidRuntime(2364): Uncaught handler: thread main exiting due to uncaught exception
02-10 11:53:07.473: ERROR/AndroidRuntime(2364): java.lang.NoClassDefFoundError: android.graphics.YuvImage
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at com.tecmark.FaceView.<init>(FaceView.java:60)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at com.tecmark.cameraView$1.onPreviewFrame(cameraView.java:111)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at android.hardware.Camera$EventHandler.handleMessage(Camera.java:395)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at android.os.Looper.loop(Looper.java:123)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at android.app.ActivityThread.main(ActivityThread.java:4363)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at java.lang.reflect.Method.invokeNative(Native Method)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at java.lang.reflect.Method.invoke(Method.java:521)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at dalvik.system.NativeStart.main(Native Method)

最佳答案

确保您以正确版本的SDK为目标。在Eclipse中,右键单击您的项目,选择“属性”,然后选择“ Android”。应该选择Api 8作为项目的构建目标。

您还应该在清单xml中设置最小的SDK属性(尽管这与错误无关)。

09-10 15:51