好的,所以我想弄清楚如何调整此代码以保存图像而不是 /sdcard 我想将其保存在 /sdcard/folder/Screenshot_xxxxx.jpg 之类的地方,
这是下面的代码。
case R.id.settings_capture:
item.setIcon(R.drawable.capture);
//Resize the webview to the height of the webpage
int pageHeight = web.getContentHeight();
LayoutParams browserParams = web.getLayoutParams();
web.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, pageHeight));
//Capture the webview as a bitmap
web.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(web.getDrawingCache());
web.setDrawingCacheEnabled(false);
//Create the filename to use
String randomFilenamepart = String.valueOf(new SecureRandom().nextInt(1000000));
String filename = Environment.getExternalStorageDirectory().toString() + "/ScreenShot_" + randomFilenamepart + ".jpg";
File imageFile = new File(filename);
//Stream the file out to external storage as a JPEG
OutputStream fout = null;
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fout);
fout.flush();
fout.close();
Toast.makeText(WebViewClientDemoActivity.this, "Screen Capture Saved!\n\nImage Saved at location : /sdcard\n\nSaved As: ScreenShot_xxxxx.jpg", Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(WebViewClientDemoActivity.this, "Problem with Capturing Image or Location to Store Image", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
} finally {
web.setLayoutParams(browserParams);
}
所以我的主要目标是将代码修改为我可以将其保存在特定位置的位置,例如 sdcard 上的应用程序自己的文件夹。
感谢任何帮助、评论、源代码示例、外部链接。我提前感谢它。