在这个问题ImageView will reset to original state after rotating中,我知道如何旋转imageView并在旋转后保留它。
但是现在,我需要根据旋转的图像进行一些缩放。缩放时,图像将在旋转前重置为原始图像,这不是我想要的。
所以我希望在旋转后从ImageView获取位图,让ImageView使用新的位图。问题是:
旋转后如何从ImageView获取位图?
答案 0 :(得分:1)
从imageview获取位图:
imageview.buildDrawingCache();
Bitmap bm=imageview.getDrawingCache();
将其保存在文件中:
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) {
}