在安装

时间:2018-09-02 08:00:43

标签: android

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

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

有什么办法吗?

1 个答案:

答案 0 :(得分: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);