0
我有應用程序捕獲圖像並將其與覆蓋圖像一起保存。拍攝照片上方的圖像就像中心有透明部分的邊框。問題是,在某些設備上的圖片被打破,看起來像這樣
某些設備上的照相機圖像保存不正確
所以棕色邊界是確定的,但拍攝的圖像是不正常。具體來說,它在HTC sense 3.6(Android 4.0.3) 上重現。首先,我捕獲圖像並創建帶有邊框的位圖。比我將它保存在SD卡上並在下一個活動中顯示它。在這裏我的代碼:
private class CameraPictureCallback implements Camera.PictureCallback {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = PictureStorage.getOutputMediaFile(PictureStorage.MEDIA_TYPE_IMAGE);
if (pictureFile == null) {
Logger.getInstance().log("Error creating media file, check storage permissions: ");
return;
}
if (data != null) {
Bitmap border = BitmapFactory.decodeResource(getResources(), R.drawable.photo_frame);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 4;
Bitmap origin_bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, opts);
Matrix matrix = new Matrix();
matrix.postRotate(mRotation);
//Border is 640x640px
Bitmap bitmap = Bitmap.createScaledBitmap(origin_bitmap, border.getWidth(), border.getHeight(), false);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
Bitmap resultBitmap = Bitmap.createBitmap(border.getWidth(), border.getHeight(), Bitmap.Config.ARGB_8888);
Canvas s = new Canvas(resultBitmap);
s.drawBitmap(bitmap, 0f, 0f, null);
s.drawBitmap(border, 0f, 0f, null);
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
if (resultBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
fos.close();
}
resultBitmap.recycle();
bitmap.recycle();
border.recycle();
origin_bitmap.recycle();
Intent i = new Intent(getContext(), PictureConfirmActivity.class);
i.putExtra("filename", pictureFile.getPath());
getContext().startActivity(i);
} catch (FileNotFoundException e) {
Logger.getInstance().log(e);
} catch (IOException e) {
Logger.getInstance().log(e);
}
}
}
}
它不會複製任何我的設備上,但問題是很實際的,我需要解決它。我可以想象它可以在這裏,resultBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)
,但它只是一個想法