我正在创建图像预览,我希望获得非常高的图片分辨率。但是,我不知道为什么,尽管 Galaxy Nexus 支持多种分辨率(我认为最大的分辨率是 1920x1080,但我不记得这些是否是确切值),当我保存图片时,它说来自预览的信息是 320x240。
pixels.mCamera = getCameraInstance();
Camera.Parameters params = mCamera.getParameters();
List<Size> sizes = params.getSupportedPreviewSizes();
Size biggestSize = sizes.get(0);
double biggestPixels = biggestSize.width + biggestSize.height;
for (Size size : sizes) {
double pixels = size.width * size.height;
if (pixels > biggestPixels) {
biggestSize = size;
biggestPixels = pixels;
}
}
// At this point, biggestSize is 1920x1080
float ratio = ((float) biggestSize.width)
/ ((float) biggestSize.height);
params.setPreviewSize(biggestSize.width, biggestSize.height);
mCamera.setParameters(params);
setCameraDisplayOrientation(this, 0, mCamera);
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
LinearLayout innerWrapper = (LinearLayout) findViewById(R.id.innerWrapper);
LayoutParams layoutParams = (LayoutParams) innerWrapper
.getLayoutParams();
layoutParams.height = (int) (layoutParams.height * ratio);
innerWrapper.setLayoutParams(layoutParams);
preview.addView(mPreview);
那innerWrapper
东西是显示一个正方形的图片。setCameraOrientation
使图像与比例对齐。拍照时,我使用自动对焦,然后...
mCamera.autoFocus(new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
mCamera.takePicture(null, null, new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0,
data.length, options);
Bitmap finalBitmap;
float ow = bitmap.getWidth();
float oh = bitmap.getHeight();
// At this point, ow and oh are 320 and 240
float ratio = ow / oh;
int fw, fh, x, y, angle;
//It continues, but irrelevant
...
这与FrameLayout
我用来保存预览的布局尺寸有关吗?因为我将它定义为 350x350 dp,所以预览应该更大。