【问题标题】:Captured Image from my application get rotated in only samsung device从我的应用程序捕获的图像仅在三星设备中旋转
【发布时间】:2014-08-29 13:01:27
【问题描述】:

我正在开发相机应用程序,我在不使用设备相机的情况下拍照,我已经这样做了,它工作正常,但是当我们在三星设备上捕获图像时,我将旋转的图像转换为 onPictureTaken 回调方法。

请让我知道我应该怎么做才能获得与设备方向相同方向的图像。

我正在使用以下代码来设置相机旋转,但它在三星设备中没有帮助。

        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
        int rotation = this.getWindowManager().getDefaultDisplay().getRotation();
        int degrees = 0;
        switch (rotation) {
        case Surface.ROTATION_0: degrees = 0; break; //Natural orientation
        case Surface.ROTATION_90: degrees = 90; break; //Landscape left
        case Surface.ROTATION_180: degrees = 180; break;//Upside down
        case Surface.ROTATION_270: degrees = 270; break;//Landscape right
        }
        int rotate = (info.orientation - degrees + 360) % 360;

        Camera.Parameters param = mCamera.getParameters();
        param.setRotation(rotate); 
        mCamera.setParameters(param);

【问题讨论】:

    标签: android


    【解决方案1】:

    我有一个有趣的建议,我在我的一个项目中也这样做了。我假设您使用的是 imageView 和 Bitmap。现在将您的旋转代码转换为旋转 90 度的方法。然后在图像上添加一个透明按钮。每次点击图片(按钮也是),图片会旋转 90 度!! 比如可以这样写一个旋转的方法;

    public static Bitmap rotateBitmap(Bitmap source)
    {
          Matrix matrix = new Matrix();
          matrix.postRotate(90);
          return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
    }
    

    然后,假设您在图像上添加了一个透明按钮“旋转器”,您可以将其设置为 onClickListener,如下所示。它同时设置了 Bitmap 和 imageView。

    rotater.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                originalBitmap=rotateBitmap(originalBitmap);
                imageView.setImageBitmap(originalBitmap);
    
            }
        });
    

    图像旋转是一个问题,因为图像的 EXIF 数据。希望这个技巧能满足你的需要。

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 2018-05-26
      • 1970-01-01
      • 2017-03-08
      • 2017-10-13
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      相关资源
      最近更新 更多