これらの回答のいくつかは質問に答えるかもしれませんが、私はそれらのどれも好きではなかったので、これを書くことになりました.これはコミュニティの助けになります.
Bitmap
アセットから取得:
public Bitmap loadBitmapFromAssets(Context context, String path)
{
InputStream stream = null;
try
{
stream = context.getAssets().open(path);
return BitmapFactory.decodeStream(stream);
}
catch (Exception ignored) {} finally
{
try
{
if(stream != null)
{
stream.close();
}
} catch (Exception ignored) {}
}
return null;
}
Drawable
アセットから取得:
public Drawable loadDrawableFromAssets(Context context, String path)
{
InputStream stream = null;
try
{
stream = context.getAssets().open(path);
return Drawable.createFromStream(stream, null);
}
catch (Exception ignored) {} finally
{
try
{
if(stream != null)
{
stream.close();
}
} catch (Exception ignored) {}
}
return null;
}