How can I use BitmapRegionDecoder code in android 2.2.2 (Froyo)?

后端 未结 3 1618
深忆病人
深忆病人 2020-12-08 14:32

I was reading an answer to a different question on SO, in which @RomainGuy commented that one could (please correct me if I\'m paraphrasing incorrectly) back-port code from

3条回答
  •  借酒劲吻你
    2020-12-08 14:46

    You should consider BitmapRegionDecoderCompat, an API 8+ version of the standard BitmapRegionDecoder (API 10+).

    Features

    • It operates in "compat" mode on devices running API < 10 using a basic Java/Android fallback (which means it won't be as efficient/fast as the native JNI implementation of API 10+, but it will avoid ugly boilerplates and manual fallbacks).
    • It uses the native JNI implementation when running on API 10+.
    • It adds extra usuful methods like decodeBestRegion(), which extracts the "best" image subregion given your parameters (gravity, size). This method also works on API < 10.

    Download

    In order to use it in your project you can manually download and add the library as an AAR file:

    or you can add the dependecy in your build.gradle (requires jCenter repository):

    dependencies {
        //...your dependecies
        compile 'org.bonnyfone:brdcompat:0.1'
    }
    

    Usage

    As stated in the docs, in order to migrate to BRDCompat you just need to change the base class name from BitmapRegionDecoder to BitmapRegionDecoderCompat:

    //BitmapRegionDecoder brd = BitmapRegionDecoder.newInstance(...);
    BitmapRegionDecoderCompat brd = BitmapRegionDecoderCompat.newInstance(...);
    

提交回复
热议问题