为Android旋转文件中的图像

为Android旋转文件中的图像,android,image,file,bitmap,rotation,Android,Image,File,Bitmap,Rotation,我在剪切图像之前尝试旋转图像时遇到问题。我尝试在要旋转的图像视图上调用setRotation,它成功地旋转了图像视图。我意识到这不是一个解决方案,因为当我调用CropImageIntentBuilder时,它在原始图像视图中传递,没有任何旋转 在下面的代码中,我尝试了一种不同的方法,将图像保存到一个文件中,并将该文件传递给CropImageIntentBuilder,但仍然存在相同的问题。请让我知道,如果有任何建议,你可以提供在这方面,或者如果我的做法是错误的。此外,如果我需要发布更多的应用程序

我在剪切图像之前尝试旋转图像时遇到问题。我尝试在要旋转的图像视图上调用
setRotation
,它成功地旋转了图像视图。我意识到这不是一个解决方案,因为当我调用CropImageIntentBuilder时,它在原始图像视图中传递,没有任何旋转

在下面的代码中,我尝试了一种不同的方法,将图像保存到一个文件中,并将该文件传递给CropImageIntentBuilder,但仍然存在相同的问题。请让我知道,如果有任何建议,你可以提供在这方面,或者如果我的做法是错误的。此外,如果我需要发布更多的应用程序代码,请让我知道

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


private void executeCropImageIntent() {
    //This is the cropIntent that is called using nexuss 10
    try{
         bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(mSingleton.mCropFileTemp.toURI().toString()));
        //mSelectedImage.setImageBitmap(rotateBitmap(bitmap, 90));
        rotateBitmap(bitmap, 90);
        try{

            FileOutputStream fOut = new FileOutputStream(mSingleton.mCropFileTemp);
            bitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
            fOut.flush();
            fOut.close();}
        catch (Exception e) {
            e.printStackTrace();
            Log.i(null, "Save file error!");
    //      Toast.makeText(this, getResources().getString(R.string.messageMissingGPS), Toast.LENGTH_LONG).show();
        }

        }

    catch (IOException e) {
        Log.d("JudgeMainFragment", "cannot take picture", e);
    }

            CropImageIntentBuilder intentBuilder = new CropImageIntentBuilder(0, 0, 0, 0, Uri.parse(mSingleton.mCropFileTemp.toURI().toString()));
            //  intentBuilder.setSourceImage(Uri.parse(mData.getImage()));
            intentBuilder.setSourceImage(Uri.parse(mSingleton.mCropFileTemp.toURI().toString()));
            startActivityForResult(intentBuilder.getIntent(this), IJudgeSingleton.REQUEST_CODE_CROP_IMAGE);


    }

您正在调用
rotateBitmap(位图,90)。但不将返回的
位图
分配给任何变量。然后您使用的是未旋转的旧位图。所以改变这条线

rotateBitmap(bitmap, 90);
进入这个

bitmap = rotateBitmap(bitmap, 90);

你,我的朋友,这个答案真是太棒了,谢谢你,它真是魅力四射。我已经为此挣扎了好几天,所以最后我决定继续努力,在不到一天的时间里得到了答案。我会支持这个答案,但我的声望还不够高。再次感谢这真的很有帮助。是的,也许,但我该怎么做呢?