android - 尝试旋转图像时 : Cannot resolve method mtx. postRotate(int)

标签 android image matrix bitmap rotation

我正在根据相机 Intent 拍摄图像,但问题是,即使我以纵向模式拍摄图像,它也会以横向模式出现。

为了解决这个问题,我尝试旋转图像,但收到此错误(下面提到)。

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        int screenWidth = getResources().getDisplayMetrics().widthPixels;
        int screenHeight = getResources().getDisplayMetrics().heightPixels;
        File imgFile = new  File(pictureImagePath);
        if(imgFile.exists()){
            Bitmap bm = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

            //Rotate image
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                // Notice that width and height are reversed
                Bitmap scaled = ScalingUtilities.createScaledBitmap(bm, screenHeight, screenWidth, ScalingUtilities.ScalingLogic.FIT);
                int w = scaled.getWidth();
                int h = scaled.getHeight();
                // Setting post rotate to 90
                Matrix mtx = new Matrix(); 
                mtx.postRotate(90); //Cannot resolve method 'postRotate(int)'
                // Rotating Bitmap
                bm = Bitmap.createBitmap(scaled, 0, 0, w, h, mtx, true);
            }else{// LANDSCAPE MODE
                //No need to reverse width and height
                Bitmap scaled = ScalingUtilities.createScaledBitmap(bm, screenHeight, screenWidth, ScalingUtilities.ScalingLogic.FIT);
                bm=scaled;
            }

            ImageView myImage = (ImageView) findViewById(R.id.imageView);
            myImage.setImageBitmap(bm);

        }
    }

问题:mtx.postRotate(90); 显示:无法解析方法“postRotate(int)”

有什么帮助吗?

欢迎提出修改建议。如有任何帮助,我们将不胜感激。

最佳答案

Bitmap.createBitmap需要android.graphics.Matrix时,您很可能会导入android.opengl.Matrix

这就是您出现编译错误的原因。

关于android - 尝试旋转图像时 : Cannot resolve method mtx. postRotate(int),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36110893/

相关文章:

android - R8 将抽象类的 "protected"方法更改为 "public"而没有 -allowaccessmodification 标志

android - 将 iPhone 移植到 Android 应用程序 - 首选项

django - 如何在 Django 中处理动态图像?

matlab - MATLAB 中的逐元素矩阵复制

游戏 Ruzzle 中使用的算法

android - 在自定义 View 中使用 animatedVectorDrawable

java - 在 Android 中选择项目后如何关闭弹出 ListView

html - 按比例(动态但没有固定图像尺寸)将完整图像调整为 div 容器,而不拉伸(stretch)到容器的每一侧

html - 手机横屏模式部分图片抖动

java - 用于在矩阵中搜索模式的算法或 Java 代码