Hallo ich würde es in etwas so machen.
Code
PhotoResult photoResult=fotoapparat.takePicture();
PendingResult<BitmapPhoto> pr = photoResult.toBitmap();
try {
Bitmap bitmap = pr.await().bitmap;
bitmap = propScaleBitmap(bitmap,760);
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
Alles anzeigen
Code
public Bitmap propScaleBitmap(Bitmap bitmap, int newDimension ) {
if (bitmap == null) {
return null;
}
float xyRatio = 0;
int newWidth = 0;
int newHeight = 0;
if(bitmap.getWidth() > bitmap.getHeight()) {
xyRatio = (float) newDimension / bitmap.getWidth();
newHeight = (int) (bitmap.getHeight() * xyRatio);
bitmap = Bitmap.createScaledBitmap(
bitmap, newDimension, newHeight, true);
} else {
xyRatio = (float) newDimension / bitmap.getHeight();
newWidth = (int) (bitmap.getWidth() * xyRatio);
bitmap = Bitmap.createScaledBitmap(
bitmap, newWidth, newDimension, true);
}
return bitmap;
}
Alles anzeigen