我在三星S4自定义摄像头有这个奇怪的问题。我测试过的所有其他设备都能正常工作,即使在S4 mini上也是如此。S4用自定义摄像头拍摄的照片损坏
拍摄的照片看起来是这样的:
有这些白色的条纹,可能这些是什么呢?
的代码没有什么奇怪的,我想......
@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
}
}
尝试使用较低的分辨率。我用我的CWAC-Camera库遇到了这种行为,我的临时结论是有些设备在最大分辨率上撒谎。 – CommonsWare