Android 矩阵。图像旋转中的后旋转(90)

Android 矩阵。图像旋转中的后旋转(90),android,rotation,imageview,Android,Rotation,Imageview,我只能旋转图像一次,当我再次单击按钮时,图像冻结且不旋转。请帮帮我 try{ //Bitmap bMap; //Get ImageView from layout xml file img = (ImageView) findViewById(R.id.imageView01); //Decode Image using Bitmap factory. Bitmap bMap = BitmapFactory.decodeFile(selectedIma

我只能旋转图像一次,当我再次单击按钮时,图像冻结且不旋转。请帮帮我

try{
    //Bitmap bMap;

    //Get ImageView from layout xml file
    img = (ImageView) findViewById(R.id.imageView01);

    //Decode Image using Bitmap factory.
    Bitmap bMap = BitmapFactory.decodeFile(selectedImagePath);

    //Create object of new Matrix.
    Matrix matrix = new Matrix();

    //set image rotation value to 90 degrees in matrix.
    matrix.postRotate(90);

    //Create bitmap with new values.
    Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), matrix, true);

    //put rotated image in ImageView.
    img.setImageBitmap(bMapRotate);

    Context context = getApplicationContext();
    CharSequence text = "Image Rotated" ;
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(context, text, duration);

    toast.show();

}catch (Exception e) {       
    e.printStackTrace();
    displayExceptionMessage(e.getMessage());
}
试试这个

try {
    //Bitmap bMap;

    //Get ImageView from layout xml file
    img = (ImageView) findViewById(R.id.imageView01);

    //Decode Image using Bitmap factory.
    //Bitmap bMap = BitmapFactory.decodeFile(selectedImagePath);
     Bitmap bMap = Bitmap.createBitmap(img.getDrawingCache());

    //Create object of new Matrix.
    Matrix matrix = new Matrix();

    //set image rotation value to 90 degrees in matrix.
    matrix.postRotate(90);
    matrix.postScale(0.5f, 0.5f);

    int newWidth = bMap.getWidth()/2;
    int newHeight = bMap.getHeight()/2;

    //Create bitmap with new values.
    Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, newWidth, newHeight, matrix, true);

    //put rotated image in ImageView.
    img.setImageBitmap(bMapRotate);

    Context context = getApplicationContext();
    CharSequence text = "Image Rotated" ;
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(context, text, duration);

    toast.show();

} catch (Exception e) {       
    e.printStackTrace();
    displayExceptionMessage(e.getMessage());
}
我在代码中所做的是从ImageView创建了一个用于旋转的位图


希望这有帮助。

下次您必须旋转已经旋转的图像,而不是原始图像,它不会对再次旋转原始图像产生任何影响。是否必须从imageView获取图像并再次旋转?但是如何。。你能给我看看吗,因为我是android新手。谢谢,这取决于你到底想实现什么,从imageView获取图像将是一个更好的选择。实际上,我正在将图像从gallery导入imageView,以执行旋转和剪切。这是预图像到文本处理的步骤,我将使用旋转和裁剪的图像来获得文本。哇。。这很有效。。非常感谢你。。我真的很感激你的帮助。。顺便说一句,您能告诉我如何执行加载到imageView中的图像的裁剪操作吗?这是提高OCR的功能之一,因为用户只会选择文本区域,而忽略不包含任何文本的其他部分。谢谢,你的意思是你想在插入图像视图之前裁剪或缩放图像?旋转后裁剪图像。检查我的编辑。。。矩阵后量表(0.5f,0.5f);int newWidth=bMap.getWidth()/2;int newHeight=bMap.getHeight()/2;位图bMapRotate=Bitmap.createBitmap(bMap,0,0,newWidth,newHeight,matrix,true)。。图像将被裁剪为newWidth和newHeight。谢谢您的裁剪功能。但是如何显示裁剪区域(一个框)供用户裁剪并设置图像大小,以便可以将图像裁剪成任何大小。。