【发布时间】:2012-08-04 11:25:59
【问题描述】:
我有一个按钮, 我希望当我点击它时,图像会保存到 sd 卡中(或内部存储,如 htc one x 我们没有像 sd 卡这样的外部存储)
这是我的代码:
sd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
MpClick.start();
File myDir=new File("/sdcard/Saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
bitMapToShare.compress(Bitmap.CompressFormat.JPEG, 600, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
以及如何使消息中显示“您的图像已保存”。 像警报一样,但持续 2 秒然后消失
【问题讨论】:
-
Toast.makeText(this, R.string.your_message, Toast.LENGTH_SHORT).show(); 怎么样
标签: android image bitmap alert