2014-01-08 64 views
1

我在三星S4自定义摄像头有这个奇怪的问题。我测试过的所有其他设备都能正常工作,即使在S4 mini上也是如此。S4用自定义摄像头拍摄的照片损坏

拍摄的照片看起来是这样的:

enter image description here

有这些白色的条纹,可能这些是什么呢?

的代码没有什么奇怪的,我想......

@Override 
    public void onPictureTaken(byte[] data, Camera myCamera) { 
     File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE); 
     if (pictureFile == null) { 
      return; 
     } 

     try { 
      FileOutputStream fos = new FileOutputStream(pictureFile); 
      fos.write(data); 
      fos.close(); 

      resizeImage(pictureFile.getPath()); 

      Intent returnIntent = new Intent(); 
      returnIntent.putExtra("path", pictureFile.getPath()); 
      setResult(RESULT_OK, returnIntent); 
      finish(); 

     } catch (FileNotFoundException e) { 
      //stuff 
     } catch (IOException e) { 
      //stuff 
     } 
    } 

这是调整大小,可能有事情做:

private void resizeImage(String picturePath) { 
    try { 

     Bitmap bitmapIn = BitmapFactory.decodeFile(picturePath); 

     Float w = (float) bitmapIn.getWidth(); 
     Float h = (float) bitmapIn.getHeight(); 

     Float aspect = w/h; 

     if ((w * h) > 120000) { 

      Bitmap bitmapOut; 

      int neww = 400; 

      if (w < h) { 
       neww = 300; 
      } 

      Float newh = (h * neww)/w; 

      bitmapOut = Bitmap.createScaledBitmap(bitmapIn, neww, 
        newh.intValue(), false); 

      File file = getOutputMediaFile(MEDIA_TYPE_IMAGE); 
      FileOutputStream fOut; 

      fOut = new FileOutputStream(file); 
      bitmapOut.compress(Bitmap.CompressFormat.JPEG, 60, fOut); 
      fOut.flush(); 
      fOut.close(); 
      bitmapOut.recycle(); 
     } else { 

     } 

     bitmapIn.recycle(); 

    } catch (Exception e) { 
     //stuff 
    } 
} 
+0

尝试使用较低的分辨率。我用我的CWAC-Camera库遇到了这种行为,我的临时结论是有些设备在最大分辨率上撒谎。 – CommonsWare

回答

0

也许可以为你解决......

我有同样的问题,一个有趣的情况发生在三星S4!

当图像尺寸远小于预览尺寸时,会出现问题。例如:预览大小:1920 x 1080和640 x 480图片大小。所以...该设备设置图片的最大分辨率,我不知道为什么...

要解决此问题,您必须组合两种尺寸:预览尺寸和图片尺寸。对我来说还好。有两种尺寸组合,白色条纹不会出现! :-)