I want create some android camera app and I have some trouble with scaling pictures. I'm using this code
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double) w/h;
if (sizes==null) return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
// Find size
for (Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
to set
List<Size> sizes = mParameters.getSupportedPreviewSizes();
optimalSize = getOptimalPreviewSize(sizes, getResources().getDisplayMetrics().heightPixels,
getResources().getDisplayMetrics().widthPixels);
mParameters.setPreviewSize(optimalSize.width, optimalSize.height);
but i have trouble, because when I try display this picture from camera quickly in ImageView it's non scalled. How could i cut and save this picture to display in preview scale without rotating? So i need cut picture with this scale to phone size.
0 comments:
Post a Comment