在android中截取屏幕截图然后在另一个活动中使用它

时间:2015-05-13 01:54:29

标签: android bitmap screenshot

所以我已经看到了很多关于如何截取屏幕并将其保存到外部存储器的问题和答案,但我想知道的是,在我完成此操作之后,我可以将其读入下一个活动,
/> 当我再次打开应用程序时,我也将使用该图像,所以我认为捆绑不够 我知道这看起来很简单,可能会提前感谢。

2 个答案:

答案 0 :(得分:0)

您需要保存屏幕截图所保存文件的位置,并在创建新活动时将其作为字符串传递给Intent。

然后在新活动中重新打开图像文件。

答案 1 :(得分:0)

You can use intent bundle to pass the screenshot's file path between Activities, and you can use SharedPreferences to persistent the path for next time loading.

Save bitmap to external storage:

FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
String path = file.getPath();

Pass path between Activities:

intent.putExtra(PATH, path);

Persistence:

SharedPreferences sp = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
sp.edit().putString(PATH, path).commit(); //save
sp.getString(PATH, null); //read