安装时将映像存储在应用程序数据文件夹中



启动时我的应用程序中有很多静态图像, 我将类中的图像添加为Base64并在应用程序启动时对其进行编码,然后通过FileOutputStream存储在内部存储中。

我需要将这些图像作为安装应用程序的文件(无需编码(放入应用程序的数据中。

有什么办法吗?

您只需将图像文件存储在assets文件夹中,然后使用以下方法从应用程序访问它们:

public static Bitmap getImageFromAsset(Context context, String fileName) throws IOException {
InputStream in = context.getAssets().open(fileName);
Bitmap bitmap = BitmapFactory.decodeStream(in);
in.close();
return bitmap;
}

您还可以将它们存储在可绘制文件夹(如果要保留大小,则为可绘制nodpi(中,并使用它来显示ImageView.

imageView.setImageResource(R.drawable.your_image);

最新更新