Полноэкранный предварительный просмотр после изображения получен при закрытых дверях в андроиде

Я использую андроид 1.5. Вот мой код захвата изображения:

public class CaptureImage extends Activity implements SurfaceHolder.Callback{
    private Camera camera=null;
    private SurfaceHolder surfaceHolder = null;
    private boolean previewRunning = false;
    private Context thisContext = this;
    private String imageName = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.image_capture);
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_camera);
        surfaceHolder = surfaceView.getHolder();
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        Button btn =(Button) findViewById(R.id.capture_image_btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                camera.takePicture(null, picCalBac, picCalBac);
            }
        });
    }

    Camera.PictureCallback picCalBac = new PictureCallback() {

        @Override
        public void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera) {
            if (paramArrayOfByte != null) {
                //Intent intent = new Intent();
                //imageName = "myImg.jpg";
                //storeByteImage(thisContext, paramArrayOfByte, 75, imageName);
                //setResult(RESULT_OK, intent);
                //finish();
            }
        }
    };

    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
        if (previewRunning) {
            camera.stopPreview();
            }
            Camera.Parameters p = camera.getParameters();
            p.setPreviewSize(arg2, arg3);
            p.setPictureSize(800, 600);
            camera.setParameters(p);
            try {
            camera.setPreviewDisplay(surfaceHolder);
            } catch (IOException e) {
                Log.d("IOException", e.getMessage());
                }
            camera.startPreview();
            previewRunning = true;
    }

    @Override
    public void surfaceCreated(SurfaceHolder arg0) {
        camera = Camera.open();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
        camera.stopPreview();
        previewRunning = false;
        camera.release();
    }

    private boolean storeByteImage(Context mContext, byte[] imageData,
            int quality, String expName) {

        FileOutputStream fileOutputStream = null;
        try {

            BitmapFactory.Options options=new BitmapFactory.Options();
            options.inSampleSize = 1;

            Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
                    imageData.length,options);


            fileOutputStream = openFileOutput(imageName, Context.MODE_PRIVATE);


            BufferedOutputStream bos = new BufferedOutputStream(
                    fileOutputStream);

            myImage.compress(CompressFormat.JPEG, quality, bos);

            bos.flush();
            bos.close();

        } catch (FileNotFoundException e) {
            Log.d("FileNotFoundException", e.getMessage());
        } catch (IOException e) {
            Log.d("IOException", e.getMessage());
        }
        return true;
    }

Вот мой image_capture.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">

    <SurfaceView android:id="@+id/surface_camera"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_weight="1">
    </SurfaceView>
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button android:text="Capture" android:gravity="center_horizontal"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:id="@+id/capture_image_btn" />
    </LinearLayout>
</LinearLayout>

У меня есть разрешение добавленного пользователя в manifest.xml.

К этому коду получают доступ onClick от другого действия. И после того, как я нажимаю фотографию, экран остается все еще с нажатым снимком. Проблемой является окно камеры, очень маленькие приблизительно 40% высоты и ширины и предварительного просмотра, показанного после того, как на изображение нажимают, также меньше, приблизительно 80% высоты и ширины. Как сделать и (окно камеры и предварительный просмотр после щелчка) полный экран?

1
задан Prabhat 31 July 2010 в 09:33
поделиться

1 ответ

Решили эту проблему, добавив следующий код onCreate

surfaceHolder.setFixedSize(getWindow().getWindowManager()
                .getDefaultDisplay().getWidth(), getWindow().getWindowManager()
                .getDefaultDisplay().getHeight());
2
ответ дан 2 September 2019 в 22:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: