view.setDrawingCacheEnabled(true);
ビューを画像としてキャプチャするために使用できます。そして、そのためのメソッドを作成する必要があります。そして、これが私の保存方法です
void Save() {
if (null != view.getDrawable()) {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
save = view.getDrawingCache();
final File myDir = new File(folder);
myDir.mkdirs();
final Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
final String fname = "StyleMe-" + n + ".png";
file = new File(myDir, fname);
if (file.exists())
file.delete();
try {
final FileOutputStream out = new FileOutputStream(file);
save.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
Toast.makeText(getApplication(), "Image Saved",
Toast.LENGTH_SHORT).show();
} catch (final Exception e) {
Toast.makeText(getApplication(),
"Something Went Wrong check if you have Enough Memory",
Toast.LENGTH_LONG).show();
}
} else {
final Toast tst = Toast.makeText(getApplication(),
"Please Select An Image First", Toast.LENGTH_LONG);
tst.setGravity(Gravity.CENTER, 0, 0);
tst.show();
}
view.setDrawingCacheEnabled(false);
}