【问题标题】:When trying to rotate an image: Cannot resolve method mtx.postRotate(int)尝试旋转图像时:无法解析方法 mtx.postRotate(int)
【发布时间】:2016-03-20 06:31:58
【问题描述】:

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

为解决此问题,我尝试旋转图像,但出现此错误(如下所述)。

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参数类型
  • @pskink 这也显示错误,但无法弄清楚。你能详细说明一下吗?
  • 检查Bitmap.createBitmap第6个参数(Matrix m)并将其与您的mtx进行比较
  • @pskink 应该是Matrix mtx。我错过了什么吗?
  • 是的:完整的类路径:createBitmap 需要 android.graphics.Matrix 但你正在通过...?

标签: android image matrix bitmap rotation


【解决方案1】:

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

这就是你有编译错误的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 2021-03-03
    • 2018-01-15
    相关资源
    最近更新 更多