At runtime, I try to put the image in a shallow view. When I tried to use the image from the "Drawable" folder, I got a "Out of memory" error. After a quick search on stackoverflow, I found that there would be some relief if we look at the image from the assets folder. But still I get an Out of memory error at runtime.
I analyzed and found that scaling will help in solving such memory problems. The fact is that I have an image size of 1280 x 720, and the size of the device is also the same. Therefore, I feel that scaling will have no effect.
Since we have experts in this community, I would appreciate if you can help me with some suggestions / examples to solve this problem.
Scenario 1:
Using the Bitmap from Drawable folder.
backgoundImage = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.backgroundhomepage), (int) dWidth, (int) dHeight, true); /*********************************************************************************************************************************************************** 1. To get the image from asset library **************************************************************************************************************************************************************/ public Bitmap getAssetImage(Context context, String filename) throws IOException { AssetManager assets = context.getResources().getAssets(); InputStream buffer = new BufferedInputStream((assets.open("drawable/" + filename + ".png"))); Bitmap bitmap = BitmapFactory.decodeStream(buffer); return bitmap; }
Scenario 2:
Using the Bitmap from Assets Folder
backgoundImage = Bitmap.createScaledBitmap(getAssetImage(context,"backgroundhomepage"), (int) dWidth, (int) dHeight, true);
source share