Skip to content

Convert a BitmapDrawable into NinePatchDrawable at runtime.

License

Notifications You must be signed in to change notification settings

YvesCheung/NinePatchChunk

 
 

Repository files navigation

NinePatchChunk

  • Convert a BitmapDrawable into NinePatchDrawable at runtime.
  • Just like iOS ResizableImageWithCapInsets method.
Before After

Usage

  • Kotlin
//Stretch from the middle
val capInsets = Rect(bitmapWidth / 2, bitmapHeight / 2, bitmapWidth / 2, bitmapHeight / 2)
val drawable = bitmapDrawable.resizableImageWithCapInsets(capInsets)
imageView.setImageDrawable(drawable)
  • Java
//Stretch from the middle
Rect capInsets = new Rect(bitmapWidth / 2, bitmapHeight / 2, bitmapWidth / 2, bitmapHeight / 2);
NinePatchDrawable drawable = NinePatchGenerator.resizableImageWithCapInsets(bitmapDrawable, capInsets);
imageView.setImageDrawable(drawable);

Install

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.YvesCheung:NinePatchChunk:x.y.z'
}

Reference

Fork from https://github.com/Anatolii/NinePatchChunk