2014-01-08 63 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圖片大小。所以...該設備設置圖片的最大分辨率,我不知道爲什麼...

要解決此問題,您必須組合兩種尺寸:預覽尺寸和圖片尺寸。對我來說還好。有兩種尺寸組合,白色條紋不會出現! :-)