Androidはどのように生成した画像を携帯電話のアルバムに保存して表示します
1397 ワード
, , , ,
//
public void saveMyBitmap(Context context,Bitmap bitmap) {
String sdCardDir=Environment.getExternalStorageDirectory()+"/DCIM/";
File appDir =new File(sdCardDir, "HappyBirthday");
if (!appDir.exists()) {
appDir.mkdir();
}
String fileName = "HappyBirthday"+System.currentTimeMillis() + ".jpg";
File f = new File(appDir,fileName);
try {
FileOutputStream fos = new FileOutputStream(f);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(f);
intent.setData(uri);
context.sendBroadcast(intent);
, , 。