【发布时间】:2012-01-01 20:12:54
【问题描述】:
我制作了一个应用程序,它每分钟捕获一次图像并将其上传到服务器。 该应用程序在手机上运行良好,但是当我在平板电脑上运行相同的应用程序时,它会捕获图像并上传一次;下次就黑屏了。
我现在该怎么办?
【问题讨论】:
标签: android android-camera image-uploading
我制作了一个应用程序,它每分钟捕获一次图像并将其上传到服务器。 该应用程序在手机上运行良好,但是当我在平板电脑上运行相同的应用程序时,它会捕获图像并上传一次;下次就黑屏了。
我现在该怎么办?
【问题讨论】:
标签: android android-camera image-uploading
我找到了解决方案。我的相机无法在预览时设置参数。 所以我找到了一个很好的功能来设置平板电脑的相机参数。
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
// TODO Auto-generated method stub
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;
// Try to find an size match aspect ratio and 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);
}
}
// Cannot find the one match the aspect ratio, ignore the requirement
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;
}
【讨论】: