解决方案 »

  1.   

    callback里的bitmap没保存下来吧
      

  2.   

        
      Camera.Parameters parameters=camera.getParameters();  
    int imageFormat=parameters.getPreviewFormat();  
    if(imageFormat==ImageFormat.NV21){  
    YuvImage img=new YuvImage(data,ImageFormat.NV21,screenWidth,screenHeight,null);                
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    img.compressToJpeg(new Rect(0,0,screenWidth,screenHeight), 100, baos); 
    bitmapPicture = BitmapFactory.decodeByteArray(baos.toByteArray(), 0, baos.size());
                        Log.i("info", bitmapPicture.toString());
    }                
    这是callback里的代码,  然后在外边再写一个方法对bitmapPicture保存到SD卡。
      

  3.   


    然后你外边调用bitmapPicture的时候就null了?
      

  4.   

    是啊    那就是你的bitmapPicture在其他地方有被赋值掉了,或者你看看bitmapPicture = BitmapFactory.decodeByteArray(baos.toByteArray(), 0, baos.size());后,这个bitmap是否为null
      

  5.   

    问题发现了  Size size = mCamera.getParameters().getPreviewSize(); //获取预览大小
    final int w = size.width;  //宽度
    final int h = size.height;
    final YuvImage image = new YuvImage(mData, ImageFormat.NV21, w, h, null);
    ByteArrayOutputStream os = new ByteArrayOutputStream(mData.length);
    if(!image.compressToJpeg(new Rect(0, 0, w, h), 100, os)){
    Log.i("info", "return null");
    return null;
    }
    byte[] tmp = os.toByteArray();
    bitmapPicture = BitmapFactory.decodeByteArray(tmp, 0,tmp.length);      
    是因为这几句代码的执行速度太慢了,外边调用的时候,这个每次还没有执行完毕。 请问这个可以优化下吗
      

  6.   

    问题发现了  Size size = mCamera.getParameters().getPreviewSize(); //获取预览大小
    final int w = size.width;  //宽度
    final int h = size.height;
    final YuvImage image = new YuvImage(mData, ImageFormat.NV21, w, h, null);
    ByteArrayOutputStream os = new ByteArrayOutputStream(mData.length);
    if(!image.compressToJpeg(new Rect(0, 0, w, h), 100, os)){
    Log.i("info", "return null");
    return null;
    }
    byte[] tmp = os.toByteArray();
    bitmapPicture = BitmapFactory.decodeByteArray(tmp, 0,tmp.length);      
    是因为这几句代码的执行速度太慢了,外边调用的时候,这个每次还没有执行完毕。 请问这个可以优化下吗
    典型的多线程设计错误,把需要你这个bitmapPicture结果的部分安排在此代码结束之后再运行。