社区!
任务是展示壁纸。
我有一堆预上传的项目 R.drawables,但想添加选项来上传用户选项。
所以我已经更改了项目并在一切正常加载时达到状态。
但是没有图像。只是灰色背景。
我试过:
Bitmap selectedImage = null;
try {
Log.d("Logger Wallpaper Debug", String.valueOf(f1.exists()));
Log.d("Logger Wallpaper Debug", f1.toString());
File sd = Environment.getExternalStorageDirectory();
Uri myUri = Uri.parse(f1.toString());
Log.d("Logger Wallpaper Debug", String.valueOf(myUri.normalizeScheme()));
InputStream imageStream = getContentResolver().openInputStream(myUri);
selectedImage= BitmapFactory.decodeStream(imageStream);
}
catch (FileNotFoundException ex){}
Bitmap myBitmap = BitmapFactory.decodeFile(f1.getAbsolutePath());
登录此:
D/Logger Wallpaper Debug: /data/user/0/com.example.myapplication/cache/file_system/root/root/Style/Wallpapers/wp_item_a11.jpeg
D/Logger Wallpaper Debug: true
D/Logger Wallpaper Debug: /storage/emulated/0/data/user/0/com.example.myapplication/cache/file_system/root/root/Style/Wallpapers/wp_item_a1.jpeg
D/Logger Wallpaper Debug: /storage/emulated/0/data/user/0/com.example.myapplication/cache/file_system/root/root/Style/Wallpapers/wp_item_a1.jpeg
如您所见 - 路径正确加载。但图像仍然是灰色的。
我试过:
Bitmap b1 = BitmapFactory.decodeFile(f1.toString());
WallpaperImageToChange.setImageBitmap(b1);
结果一样
Picasso.get().load(Uri.parse(f1.getPath())).into(WallpaperImageToChange);
又一样。
似乎这可能是有路径的东西。
尝试从模拟器退出路径:
File f1 = new File("/data/user/0/com.example.myapplication/cache/file_system/root/root/Style/Wallpapers/wp_item_a1.jpeg");
结果相同。
WallpaperImage.setBackgroundDrawable(Drawable.createFromPath(f1.getAbsolutePath()));
也没有结果。
那么,有什么想法吗?