GithubHelp home page GithubHelp logo

Comments (5)

DebdeepG avatar DebdeepG commented on April 20, 2024

Inside createBitmapAndGcIfNecessary() , it is not favourable to create bitmap once again when oom is encountered. Instead, using bitmap options, setting inDither true and using Bitmap.Config.RGB_565 might be useful.

from shimmer-android.

ClaudeHangui avatar ClaudeHangui commented on April 20, 2024

And how will I do that ??
This is what I have so far in my catch block ?
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = true;
options.inPreferredConfig = Bitmap.Config.RGB_565;

Now I can only use BitmapFactory to create bitmap but I'm kinda stuck... The createBitmapAndGcIfNecessary() method takes the width and height of the resource but these parameters are not used when creating a bitmap using the BitmapFactory

from shimmer-android.

DebdeepG avatar DebdeepG commented on April 20, 2024

Please go through the docs link and on passing the inSampleSize, the bitmap will be scaled down by the decoder automatically. Also do take a look at the calculateInSampleSize() in the example method where you can pass your width and height.

from shimmer-android.

ClaudeHangui avatar ClaudeHangui commented on April 20, 2024

Yes...I did took a look at the link you provided...and I did added the calculateInSampleSize() method..Forgive me, but I still don't see (in the ShimmerLayout class) where are we suppose to take in the resource ..The sample assumes we are loading a bitmap into an Imageview...But our use case here is the Shimmerlayout class..
This is what I've got so far (as per the link you provided) :

private Bitmap createBitmap(int width, int height) {
        try {
            return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        } catch (OutOfMemoryError e) {
            System.gc();
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inDither = true;
            options.inPreferredConfig = Bitmap.Config.RGB_565;
            options.inSampleSize = calculateInSampleSize(options, width, height);
            options.inJustDecodeBounds = false;
            return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        }
    }
    public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
    {
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;
        if (height > reqHeight || width > reqWidth) {
            final int halfHeight = height / 2;
            final int halfWidth = width / 2;
            while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) {
                inSampleSize *= 2;
            }
        }
        return inSampleSize;
    }

from shimmer-android.

xiphirx avatar xiphirx commented on April 20, 2024

544c568

from shimmer-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.