Coder Social home page Coder Social logo

typedefmetsai / bitmapfactorycompat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from badpx/bitmapfactorycompat

0.0 2.0 0.0 481 KB

Android BitmapFactory compat library for reuse dimensions mismatch bitmap in lower than KitKat.

License: Apache License 2.0

Makefile 1.98% C++ 30.21% C 2.48% Java 65.34%

bitmapfactorycompat's Introduction

ince Andorid API Level 11(Honeycomb), BitmapFactory providing the reuse mechanism when decode bitmap: If set BitmapFactory.Options.inBitmap, then decode methods that take the Options object will attempt to reuse this bitmap when loading content.
As of KITKAT, any mutable bitmap can be reused by BitmapFactory to decode any other bitmaps as long as the resulting byte count of the decoded bitmap is less than or equal to the allocated byte count of the reused bitmap.
But prior to KITKAT additional constraints apply: The image being decoded (whether as a resource or as a stream) must be in jpeg or png format, and only equal sized bitmaps are supported. For resolved this restrict, here provides a BitmapFactory compatibility library.

Get Started

AndroidStudio/IntelliJ IDEA

First at all, import this library directory as a module into your Android project which created by AndroidStudio or IntelliJ IDEA, make sure add dependencies to your main module.

Gradle Projects

TODO.

Code sample

Just like use BitmapFactory of android framework, we set BitmapFactory.Options.inBitmap to a exists bitmap and BitmapFactory.Options.inSampleSize to 1(another restrict prior to KITKAT) for reuse the inBitmap:

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inMutable = true; // The current implementation necessitates that the reused bitmap be mutable
    mReuseBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.map, opts);

    // Now reuse above bitmap object to decode another picture:
    opts.inBitmap = mReuseBitmap;
    try {
        Bitmap image = com.badpx.BitmapFactoryCompat.BitmapFactory.decodeResource(
            getResources(), R.drawable.image, opts);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }

bitmapfactorycompat's People

Contributors

badpx avatar

Watchers

 avatar  avatar

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.