我使用表面视图进行相机操作,图像捕获后将图像数据传递给storeByteImage方法。 但对于某些设备或Android lolipop版本以上我得到的低分辨率图像。 在一些新设备中,我只获得了拍摄图像的1/4。
public boolean storeByteImage(Context mContext, byte[] imageData, int quality) {
FileOutputStream fileOutputStream = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options);
_getdate.setDrawingCacheEnabled(true);
_getdate.measure(
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
_getdate.layout(0, 0, _getdate.getMeasuredWidth(),
_getdate.getMeasuredHeight()); // set the layout of the date in the image
_getdate.buildDrawingCache(true);
_getdate.buildDrawingCache();
try {
textimage = Bitmap.createBitmap(_getdate.getDrawingCache());
} catch (Exception e) {
e.getMessage();
e.printStackTrace();
}
_getdate.setDrawingCacheEnabled(false); // clear drawing
// cache
Matrix matrix = new Matrix();
// the image height and width
int width, height;
height = myImage.getHeight();
width = myImage.getWidth();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(bitmap);
myImage = Bitmap.createScaledBitmap(myImage, width, height, true);
comboImage.drawBitmap(myImage, 0, 0, null);
comboImage.drawBitmap(textimage, matrix, null);
fileOutputStream = new FileOutputStream(
getResources().getString(R.string.sdpath_files_dir) + IMAGEFILE_EXT_JPG);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}