Android 在内存中添加图像后,如何在库中显示图像
我使用代码在内存中添加了图像Android 在内存中添加图像后,如何在库中显示图像,android,android-file,Android,Android File,我使用代码在内存中添加了图像 Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.blue_500); FileOutputStream fileOutputStream = openFileOutput("file.jpg",MODE_PRIVATE); bitmap.compress(Bitmap.CompressFormat.JPEG,80,fileOutputSt
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.blue_500);
FileOutputStream fileOutputStream = openFileOutput("file.jpg",MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG,80,fileOutputStream);
fileOutputStream.close();
但是图片没有显示在图库中这是我的代码工作
File file = Environment.getDataDirectory();
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
sendBroadcast(intent);
您正在使用emulator吗?不使用物理设备。请尝试关闭设备,然后再打开。这将使媒体扫描程序运行,以便它拾取您新创建的图像文件。请注意,这在4.4以上的Android版本(KitKat)上不起作用。此代码在棒棒糖中运行良好,但对于brodcasting,但对于将图像保存到内存,则存在代码差异