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

问题描述 投票:1回答:1

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

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

有什么办法吗?

android
1个回答
3
投票

您只需将图像文件存储在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;
}

您还可以将它们存储在drawable文件夹中(如果要保留大小,则将其存储在drawable-nodpi中)并使用它在ImageView中显示。

imageView.setImageResource(R.drawable.your_image);
© www.soinside.com 2019 - 2024. All rights reserved.