0

In this question ImageView will reset to original state after rotating, I know how to rotate an imageView and keep it after rotating.

But now, I need to do some scaling based on the rotated image. When scaling, the image will reset to original one before rotating, this is not what I want.

So I want to get the bitmap from ImageView after rotating, and let the ImageView use the new one. The question is:

How to get the bitmap from ImageView after rotating?

Community
  • 1
  • 1
Freewind
  • 193,756
  • 157
  • 432
  • 708

1 Answers1

1

To get bitmap from imageview:

  imageview.buildDrawingCache();
    Bitmap bm=imageview.getDrawingCache();

To save it in a file:

OutputStream fOut = null;
    Uri outputFileUri;
     try {
    File root = new File(Environment.getExternalStorageDirectory()
      + File.separator + "folder_name" + File.separator);
    root.mkdirs();
   File sdImageMainDirectory = new File(root, "myPicName.jpg");
    outputFileUri = Uri.fromFile(sdImageMainDirectory);
    fOut = new FileOutputStream(sdImageMainDirectory);
   } catch (Exception e) {
    Toast.makeText(this, "Error occured. Please try again later.",
      Toast.LENGTH_SHORT).show();
   }

   try {
    bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    fOut.flush();
    fOut.close();
   } catch (Exception e) {
   }
Kanaiya Katarmal
  • 5,974
  • 4
  • 30
  • 56