我想鎖定相機分辨率以拍攝640x480像素下的照片,我可以這樣做嗎?Android - 如何鎖定相機分辨率640 x 480
這需要完成,因爲大於640x480的照片會使其顯示非常慢,有時甚至會導致應用程序崩潰。
如果這不能完成,有一種方法來調整我的圖片在SD卡上的大小?
我想鎖定相機分辨率以拍攝640x480像素下的照片,我可以這樣做嗎?Android - 如何鎖定相機分辨率640 x 480
這需要完成,因爲大於640x480的照片會使其顯示非常慢,有時甚至會導致應用程序崩潰。
如果這不能完成,有一種方法來調整我的圖片在SD卡上的大小?
你甚至可以將其保存到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上)摘自