이미지 미리보기를 만들고 매우 높은 그림 해상도를 얻고 싶습니다. 그러나 Galaxy Nexus가 다양한 해상도 (특히 최대 크기는 1920x1080라고 생각하지만 그 값이 정확한지는 기억이 안납니다)를 지원하지만 왜 사진을 저장할 지에 대해서는 알려지지 않았습니다. 미리보기에서 오는 정보는 320x240입니다.카메라 미리보기는 항상 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로 정의했기 때문에 미리보기가 더 커야합니다.