Android相机屏幕尺寸

时间:2012-04-10 11:25:43

标签: android

当相机加载的时候我想打开相机的特定区域。不需要全屏打开。 enter image description here

在这里,黑色区域只显示摄像机视图。我该怎么做?

我写了这样的代码..

    public class CameraActivity extends Activity{

private static final int CAMERA_PIC_REQUEST = 15;  
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);  
    getParent().getParent().setTitle("Image Capture");

    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  
    onActivityResult(15, 0, cameraIntent);



}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == CAMERA_PIC_REQUEST) {
        }
} 

请有人帮我解决这个问题。

提前致谢..

1 个答案:

答案 0 :(得分:3)

在您的应用程序中试用此相机活动代码

protected void startCameraActivity() {
        selectedImagePath = Environment.getExternalStorageDirectory() + "/default" + image_count+ ".jpg";
        image_count++;
        File file = new File(selectedImagePath);
        Uri outputFileUri = Uri.fromFile(file);
        Intent intent = new Intent (android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, 0);
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (resultCode) {
        case -1:
        onPhotoTaken();
        break;
        }
        }
        protected void onPhotoTaken() {
        _taken = true;
        bitmap = decodeFile();
        img_logo.setImageBitmap(bitmap);

        }
        @Override
        protected void onRestoreInstanceState(Bundle savedInstanceState) {
        if (savedInstanceState.getBoolean(PHOTO_TAKEN)) {
        onPhotoTaken();
        }
        }
        @Override
        protected void onSaveInstanceState(Bundle outState) {
        outState.putBoolean(PHOTO_TAKEN, _taken);
        }
        private Bitmap decodeFile() {
        try {
        // decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream( selectedImagePath), null, o);
        final int REQUIRED_SIZE = 70;
        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
        if (width_tmp / 2 < REQUIRED_SIZE
        || height_tmp / 2 < REQUIRED_SIZE)
        break;
        width_tmp /= 2;
        height_tmp /= 2;
        scale++;
        }
        // decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        return BitmapFactory.decodeStream(new FileInputStream(selectedImagePath), null, o2);
        } catch (FileNotFoundException e) {
        }
        return null;
        }
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if(keyCode==KeyEvent.KEYCODE_BACK)
            {
                finish();
            }
            return super.onKeyDown(keyCode, event);
        } 

我希望这可以帮助你