【发布时间】:2013-08-19 22:34:23
【问题描述】:
我制作了一个按钮来截取屏幕截图并保存到图片文件夹中。我将它设置为以 capture.jpeg 的名称保存,但我希望它像这样保存,例如 cafe001.jpeg、cafe002.jpeg。另外请告诉我如何将其保存为时间 format.jpeg ? 提前感谢您的帮助
container = (LinearLayout) findViewById(R.id.LinearLayout1);
Button captureButton = (Button) findViewById(R.id.captureButton);
captureButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
container.buildDrawingCache();
Bitmap captureView = container.getDrawingCache();
FileOutputStream fos;
try {
fos = new FileOutputStream(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString() + "capture.jpeg");
captureView.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(),
"Captured under Pictures drectory", Toast.LENGTH_LONG)
.show();
}
});
【问题讨论】: