Skip to content Skip to sidebar Skip to footer

Memory Leak Error Android

InputSream backgroundBitmap; //backgroundBitmap is initialized from asset image.png immutableBitmap = BitmapFactory.decodeStream(backgroundBitmap); getting this error: java.lang.O

Solution 1:

try this.. file from asset

Filef=newFile("file:///android_assetassets/mydemo.png")

publicstatic Bitmap decodeFile(File f,int WIDTH,int HIGHT){
        try {
            //Decode image size
            BitmapFactory.Optionso=newBitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(newFileInputStream(f),null,o);

            //The new size we want to scale tofinalint REQUIRED_WIDTH=WIDTH;
            finalint REQUIRED_HIGHT=HIGHT;
            //Find the correct scale value. It should be the power of 2.int scale=1;
            while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
                scale*=2;

            //Decode with inSampleSize
            BitmapFactory.Optionso2=newBitmapFactory.Options();
            o2.inSampleSize=scale;
            return BitmapFactory.decodeStream(newFileInputStream(f), null, o2);
        }
            catch (FileNotFoundException e) {}
        returnnull;
    }

this function will scale bitmap as you pass width and height

Post a Comment for "Memory Leak Error Android"