我有一个应用程序,它可以截取视图的屏幕截图并将其保存在外部存储目录中。是否可以预览拍摄的图像?
我不想在代码中添加任何片段或布局。相反,因为我知道文件名和目录,是否可以通过我的应用程序在 android image viewer 中打开图像?
这是我的捕获代码。
public void sharePic(View v)
{
View captureView = findViewById(R.id.capture);
captureView.setDrawingCacheEnabled(true);
Bitmap bitmap = captureView.getDrawingCache();
File directory = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + "/BucketList");
directory.mkdirs();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
Date now = new Date();
String fileIns = formatter.format(now) + ".png";
File file = new File(directory, fileIns);
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
Toast.makeText(MainActivity.this, "Screen Captured", Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(MainActivity.this, "Screen Capture Error", Toast.LENGTH_SHORT).show();
}
}