How Can I Store Jpegs As Byte[] For Faster Loading?
I need to load ~150 JPEG images into ArrayList for playing an animation. If I load them like that ByteArrayOutputStream stream = new ByteArrayOutputStream(); BitmapFactory.decodeR
Solution 1:
You can use the method below to get the raw data from a resource. You don't need to decode then compress again.
byte[] getBytesFromResource(final int res) {
byte[] buffer = null;
InputStream input = null;
try {
input = getResources().openRawResource(res);
buffer = new byte[input.available()];
if (input.read(buffer, 0, buffer.length) != buffer.length) {
buffer = null;
}
} catch (IOException e) {
buffer = null;
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {}
}
}
return buffer;
}
Post a Comment for "How Can I Store Jpegs As Byte[] For Faster Loading?"