相关疑难解决方法(0)

为什么在Android上的某些设备上使用相机意图捕获的图像会被旋转?

我正在捕捉图像并将其设置为图像视图.

public void captureImage() {

    Intent intentCamera = new Intent("android.media.action.IMAGE_CAPTURE");
    File filePhoto = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
    imageUri = Uri.fromFile(filePhoto);
    MyApplicationGlobal.imageUri = imageUri.getPath();
    intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(intentCamera, TAKE_PICTURE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intentFromCamera) {
    super.onActivityResult(requestCode, resultCode, intentFromCamera);

    if (resultCode == RESULT_OK && requestCode == TAKE_PICTURE) {

        if (intentFromCamera != null) {
            Bundle extras = intentFromCamera.getExtras();
            if (extras.containsKey("data")) {
                bitmap = (Bitmap) extras.get("data");
            }
            else {
                bitmap = getBitmapFromUri();
            }
        }
        else {
            bitmap = getBitmapFromUri();
        }
        // …
Run Code Online (Sandbox Code Playgroud)

camera android image rotation android-camera-intent

344
推荐指数
11
解决办法
19万
查看次数

Android相机意图 - 内存不足错误和旋转错误

我正在创建一个Android应用程序,利用相机拍照,然后根据用户输入将它们发送到服务器.我目前在相机意图方面遇到了一些问题.我的主要问题是:

  1. 获取与拍摄位置相比似乎旋转的照片.

  2. 当我尝试修复此旋转时,我得到一个OutOfMemoryError

所以主要是我需要确保图片的方向不会改变,并且我没有得到OutOfMemoryError.

这是使用相机Intent拍摄照片的功能.

private void dispatchTakePictureIntent(int actionCode) {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File f = new File(Environment.getExternalStorageDirectory(),"/ServerApp/test.jpg");
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
        startActivityForResult(takePictureIntent, actionCode);
    }
Run Code Online (Sandbox Code Playgroud)

此功能用于旋转图像并将其保存在该旋转处.

private void getRotate() {

        String imagePath ="";
        int rotate = 0;
        File f = null;
        try {
             f = new File(Environment.getExternalStorageDirectory(),"/ServerApp/test.jpg");
             imagePath = f.getAbsolutePath();
            File imageFile = new File(imagePath);
            ExifInterface exif = new ExifInterface(
                    imageFile.getAbsolutePath());
            int orientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);

            switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = …
Run Code Online (Sandbox Code Playgroud)

android bitmap out-of-memory mediastore android-camera-intent

3
推荐指数
1
解决办法
4019
查看次数