【发布时间】:2012-01-31 18:07:18
【问题描述】:
我想锁定相机分辨率以拍摄 640x480 像素以下的照片,我可以这样做吗?
这需要完成,因为大于 640x480 的照片会使它们显示很慢,有时甚至会导致我的应用程序崩溃。
如果无法做到这一点,有什么方法可以调整我在 SD 卡上的图片大小?
【问题讨论】:
标签: android image camera resolution
我想锁定相机分辨率以拍摄 640x480 像素以下的照片,我可以这样做吗?
这需要完成,因为大于 640x480 的照片会使它们显示很慢,有时甚至会导致我的应用程序崩溃。
如果无法做到这一点,有什么方法可以调整我在 SD 卡上的图片大小?
【问题讨论】:
标签: android image camera resolution
您甚至可以在将图片保存到 SD 卡之前调整其大小。在代码中,是这样的:
Bitmap smallBitmap = Bitmap.createScaledBitmap(sourceBitmap, 640, 480, true);
调整大小后用代码保存它,我猜你已经写了保存..
如果您需要提供字节数组而不是位图来保存,您可以使用:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bMap.compress(CompressFormat.JPEG, 100, bos); // setup jpeg quality here
byte[] data = bos.toByteArray();
希望它有所帮助。 干杯
【讨论】:
您可以尝试获得尽可能低的分辨率
private Camera.Size getBestPreviewSize(int width, int height,Camera.Parameters parameters)
{
Camera.Size result=null;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
if (size.width <= width && size.height <= height) {
if (result == null) {
result=size;
}
else {
int resultArea=result.width * result.height;
int newArea=size.width * size.height;
if (newArea > resultArea) {
result=size;
}
}
}
}
return(result);
}
或者在你想要的分辨率处停止循环。
取自here(commonsguy github)
【讨论】: