gpt4 book ai didi

android - 相机预览始终返回 320x240 位图

转载 作者:行者123 更新时间:2023-11-30 03:42:23 24 4
gpt4 key购买 nike

我正在创建图像预览,我希望获得非常高的图片分辨率。然而,我不知道为什么,尽管 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,所以预览应该更大。

最佳答案

傻我。问题是我的 PictureCallback 是作为 jpeg 参数实现的,而不是 raw 参数。在哪里,引用 documentation :

The raw callback occurs when the raw image data is available (NOTE: the data will be null if there is no raw image callback buffer available or the raw image callback buffer is not large enough to hold the raw image). The postview callback occurs when a scaled, fully processed postview image is available (NOTE: not all hardware supports this). The jpeg callback occurs when the compressed image is available.

将整个 PictureCallback 移动到 mCamera.takePicture 的第二个参数而不是第三个参数将是解决问题的途径。但是,您需要 CallbackBuffer 来执行此操作并更改代码以适应缓冲区的使用。所以对于第一个版本,我会坚持使用低质量的图片。

关于android - 相机预览始终返回 320x240 位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15522213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com