10

好吧,我再次更新了我的问题,完全是这一次。

我已经在 Galaxy Nexus(JB)、Moto-XX(GB)、SAMSUNG(Froyo) 上一一测试了以下代码,出现了不同的问题/异常。

public class MainActivity extends Activity {
    @SuppressLint("NewApi")
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

          ShutterCallback shutterCallback = new ShutterCallback() {
           public void onShutter() {
                  System.out.println("shutterCallback");
           }
          };

          PictureCallback rawCallback = new PictureCallback() {
           public void onPictureTaken(byte[] data, Camera camera) {
                  System.out.println("onPictureTaken");
           }
          };

          PictureCallback jpegCallback = new PictureCallback() {
           public void onPictureTaken(byte[] data, Camera camera) {
                  System.out.println("jpegCallback");
                  FileOutputStream outStream = null;
                  try {
                  System.out.println("jpegCallback begin");
                     camera.startPreview();
                     File storagePath =  new File("/mnt/sdcard/");
                     File myImage = new File(storagePath, "example2.jpg");
                     outStream = new FileOutputStream(myImage); 
                     outStream.write(data);
                     outStream.close();
                    } catch (FileNotFoundException e) {
                          System.out.println("jpegCallback FileNotFoundException");
                     e.printStackTrace();
                    } catch (IOException e) {
                          System.out.println("jpegCallback IOException");
                     e.printStackTrace();
                    } finally {
                     camera.stopPreview();
                     camera.release();
                    }
            }
          };

          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
              for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
              Camera.CameraInfo info = new Camera.CameraInfo();
              Camera.getCameraInfo(i, info);
              if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                     try{
                             Camera camera = Camera.open(i);
                             Camera.Parameters parameters = camera.getParameters();
                             camera.setParameters(parameters);
                              camera.startPreview();
                             camera.setPreviewDisplay(null);
                              System.out.println("takePicture ahead");
                             camera.takePicture(null, rawCallback, jpegCallback);
                              System.out.println("takePicture finish");
                            }
                            catch (Exception e){
                                  System.out.println("printStackTrace");
                                     e.printStackTrace();
                            }
                    }
                }
            }  
    }

具体问题如下:


在 Android4.1&4.2中,有三部分异常:
1.由“Camera camera = Camera.open(i);”引起

11-26 00:36:29.144: D/DOMX(132): ERROR: failed check:status >= 0 - returning error: 0x81000 - Can't connect
11-26 00:36:29.144: D/DOMX(132): ERROR: failed check:eRPCError == RPC_OMX_ErrorNone - returning error: 0x80001001 - Error initializing RPC
11-26 00:36:29.144: D/DOMX(132): ERROR: failed check:hRPCCtx != NULL - returning error: 0x81001 - NULL context handle supplied to RPC Deinit
11-26 00:36:29.144: D/DOMX(132): ERROR: rror in Initializing Proxy
11-26 00:36:29.144: E/CameraHAL(132): OMX_GetHandle() failed, error: 0x80001001

2.由“camera.startPreview();”引起

11-26 00:36:30.488: D/DOMX(132): ERROR: failed check:(eError == OMX_ErrorNone) || (eError == OMX_ErrorNoMore) - returning error: 0x80001005 - Error returned from OMX API in ducati
11-26 00:36:30.488: E/CameraHAL(132): Error while configuring rotation 0x80001005

3.由“camera.takePicture()”引起

11-26 00:36:30.495: E/CameraHAL(132): Adapter state switch INTIALIZED_STATE Invalid Op! event = 0x13
11-26 00:36:30.738: D/DOMX(132): ERROR: failed check:(eError == OMX_ErrorNone) || (eError == OMX_ErrorNoMore) - returning error: 0x80001005 - Error returned from OMX API in ducati
11-26 00:36:30.738: E/CameraHAL(132): Exiting function UseBuffersCapture because of ret 0 eError=80001005

因此,结果是,即使在 Galaxy Nexus i9250 等普通设备中,照片也不是在 Jelly Bean 中拍摄的


接下来在 Android2.3中,有两部分异常:
1.caused by "Camera camera = Camera.open(i);"

E/CameraSettings(1235): Param type 53 not supported        
E/CameraSettings(1235): Param type 51 not supported        
E/CameraSettings(1235): Param type 50 not supported  

2.尽管如此,camera.takePicture() 仍然可以执行。结果显示照片被拍了。除了一个问题:“E/MemoryHeapBase(1235): mmap(fd=50, size=0) failed (Invalid argument)”

11-26 01:28:33.835: I/AwesomePlayer(1235): prepareAsync_l
11-26 01:28:33.835: D/CameraHal(1235): Capture size 2048x1536, res enum 3
11-26 01:28:33.835: I/AwesomePlayer(1235): prepareAsync_l
11-26 01:28:33.835: D/CameraHal(1235): Setting capture format 0 header 2
11-26 01:28:33.835: I/HPAndroidHAL(1235): APILOG: SetCaptureDataFormat (1 2 0)
11-26 01:28:33.835: D/CameraHal(1235): Thumbnail enabled
11-26 01:28:33.843: E/MemoryHeapBase(1235): mmap(fd=50, size=0) failed (Invalid argument)
11-26 01:28:33.843: D/CameraHal(1235): Initializing capture memory raw: 0x42ee6000 (6295552), jpg: 0x434e7000 (3147776), pv 0xffffffff (0)
11-26 01:28:33.843: I/HPAndroidHAL(1235): APILOG: InitializeCaptureMemory(3 3147776 0x434e7000 6295552 0x42ee6000 0 0xffffffff)
11-26 01:28:33.843: I/HPAndroidHAL(1235): APILOG: InitializeCaptureMemoryBuffers(3 1 0_0x42de5d9c 6295552_0x42de5dc0 3147776_0x42de5d94 0_0x42de5dc8)
11-26 01:28:33.843: I/HPAndroidHAL(1235): APILOG: SetCaptureS2 with finish3A = 1
11-26 01:28:33.843: I/VorbisDecoder(1235): mNumChannels=1, mSampleRate=44100
11-26 01:28:33.843: E/OMXCodec(1235): Successfully allocated software codec 'VorbisDecoder'
11-26 01:28:33.843: I/VorbisDecoder(1235): mNumChannels=1, mSampleRate=44100
11-26 01:28:33.843: E/OMXCodec(1235): Successfully allocated software codec 'VorbisDecoder'
11-26 01:28:33.851: I/AwesomePlayer(1235): play_l
11-26 01:28:33.851: I/AwesomePlayer(1235): play_l
11-26 01:28:33.874: I/AwesomePlayer(1235): pause_l 1
11-26 01:28:33.874: I/AwesomePlayer(1235): reset_l
11-26 01:28:33.874: I/ExtendFileSource(1235): release pFilename = 0xfb690
11-26 01:28:33.874: I/AwesomePlayer(1235): reset_l
11-26 01:28:33.874: I/AwesomePlayer(1235): reset_l
11-26 01:28:33.882: I/AwesomePlayer(1235): pause_l 1
11-26 01:28:33.882: I/AwesomePlayer(1235): reset_l
11-26 01:28:33.882: I/ExtendFileSource(1235): release pFilename = 0xf9098
11-26 01:28:33.882: I/AwesomePlayer(1235): reset_l
11-26 01:28:33.882: I/AwesomePlayer(1235): reset_l

因此,在Android2.3中,拍照后都不会调用shutterCallback、rawCallback和jpegCallback中的任何一个


之后,在 Android2.2中,拍照后会调用 shutterCallback 和 rawCallback。但他们都不能为我提供数据(字节流)。如http://developer.android.com/reference/android/hardware/Camera.html#takePicture(android.hardware.Camera.ShutterCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback)中介绍的 ,如果没有可用的原始图像回调缓冲区或原始图像回调缓冲区不足以容纳原始图像,则数据将为空。而且我确实在 rawCallback 中得到了空数据


这都是硬件不兼容还是代码故障造成的?
请帮忙

4

3 回答 3

2

希望你现在已经解决了你的问题,但我认为你遇到的问题是你将相机预览设置为空,它需要一个有效SurfaceView的预览来​​打开闪光灯(至少在 Galaxy Nexus和其他一些三星设备......)

罪魁祸首:

 camera.setPreviewDisplay(null);

可能的解决方案:

将 a 添加SurfaceView到您的布局中,并将其大小指定为 1px x 1px。似乎它必须至少那么大(大小为 0 会产生不同的错误)。SurfaceView关闭屏幕(滚动RelativeLayout或其他)可能会奏效

于 2013-01-23T20:16:09.763 回答
1

好的,这不是一个答案,但我不能发表评论,所以我会以这种形式尝试一下:我可以确认你在我的 Galaxy Nexus 上遇到的例外情况。

除此之外,但可能有点帮助,如果我希望我的图片不是黑色的,我必须在 startPreview 和 takePicture 之间添加一个 Thread.Sleep(500) 。

也就是说,我正在读取两台摄像机(按顺序读取,因为同时尝试只是不起作用),有时一台摄像机工作,另一台产生错误,有时两者都工作,有时没有工作。

  1. 解决回调不被调用的问题:释放相机并重试。它通常有效。
  2. 解决旋转 0x80001005 的问题:重新启动应用程序/服务
  3. RPC_OMX 问题:这似乎与我第一次购买这款手机时的经历非常相似。它安装了 4.0.2,偶尔,相机会“迷路”——就好像我不在那里一样。在这种情况下,只有手机重启有帮助。
于 2013-03-23T06:56:40.923 回答
0

尝试放置一个 if 语句来测试您使用的文件路径是否是这样的真实目录

if(file.isDirectory()){

    Log.w("file test---->","filepath is good");

}else{

    Log.w("file test---->","filepath is bad");

 }

仅仅说“sdcard”通常是一个坏主意,因为它在多个设备上是不同的。您最好创建自己的目录来存储文件。

于 2012-11-25T00:07:58.640 回答