我想在捕获图像时运行媒体扫描仪.捕获后,图像在网格视图中更新.为此,我需要运行媒体扫描仪.我找到了两个运行媒体扫描程序的解决方案,一个是广播 事件,另一个是运行媒体扫描程序类.我认为在Ice Cream Sandwich(4.0)中引入了媒体扫描程序类.在版本之前需要设置广播事件来运行媒体扫描程序.
任何人都可以指导我如何以正确的方式运行媒体扫描仪.
android android-camera android-gridview android-mediascanner
在我的应用程序中,您需要将照片保存到SD卡,然后用户可以选择如何处理它.删除,保存或发送.如果按删除键.File.delete()当我在画廊中查看时,我称之为删除文件,然后当我稍后回去时,我看到一个黑色图像,说文件无法加载.该图像是我之前尝试删除的图像.这有什么问题,为什么它不会完全消失?
我如何保存图像:
public static File getOutputMediaFile(byte[] data){
image= BitmapFactory.decodeByteArray(data, 0, data.length);
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "FrontFlash");
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()){
if (!mediaStorageDir.mkdirs()) return null;
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
return mediaFile;
}
@Override
public void onPictureTaken(byte[] data, Camera camera){
pictureFile = Util.getOutputMediaFile(data);
if (pictureFile == null){
Toast.makeText(this, …Run Code Online (Sandbox Code Playgroud) 我从API获取Image作为BLOB类型.而且,我保存如下,
public static void setOptimalImage(Context ctx, File file, ImageView iv,
Point size) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getPath(), options);
if (options.outHeight > 0 && options.outWidth > 0) {
if (size == null) {
size = new Point();
WindowManager wm = (WindowManager) ctx
.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getSize(size);
}
options.inSampleSize = Utils.calculateInSampleSize(options, size.x,
size.y);
options.inJustDecodeBounds = false;
try {
iv.setImageBitmap(BitmapFactory.decodeFile(file.getPath(),
options));
} catch (OutOfMemoryError oome) {
Log.e(Utils.class.getName(),
oome.getMessage() == null ? "OutOfMemory error: "
+ file.getName() : oome.getMessage());
}
} …Run Code Online (Sandbox Code Playgroud)