diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java index b12e5a1e..bf72f276 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java @@ -93,6 +93,7 @@ public class ImageNode extends ViewNode { private int placeHolderColor = Color.TRANSPARENT; private int errorColor = Color.TRANSPARENT; private JSObject stretchInset = null; + private JSObject tileInset = null; private float imageScale = DoricUtils.getScreenScale(); private Animatable2Compat.AnimationCallback animationCallback = null; @@ -161,6 +162,10 @@ public class ImageNode extends ViewNode { if (stretchInsetValue.isObject()) { this.stretchInset = stretchInsetValue.asObject(); } + JSValue tileInsetValue = jsObject.getProperty("tileInset"); + if (tileInsetValue.isObject()) { + this.tileInset = tileInsetValue.asObject(); + } JSValue imageScaleValue = jsObject.getProperty("imageScale"); if (imageScaleValue.isNumber()) { this.imageScale = imageScaleValue.asNumber().toFloat(); @@ -371,6 +376,27 @@ public class ImageNode extends ViewNode { (int) (bitmap.getHeight() - bottom) ); + NinePatchDrawable ninePatchDrawable = new NinePatchDrawable( + getContext().getResources(), + bitmap, + DoricUtils.getNinePatchChunk(rect), + rect, + null + ); + super.setResource(ninePatchDrawable); + } else if (tileInset != null) { + float left = tileInset.getProperty("left").asNumber().toFloat() * scale; + float top = tileInset.getProperty("top").asNumber().toFloat() * scale; + float right = tileInset.getProperty("right").asNumber().toFloat() * scale; + float bottom = tileInset.getProperty("bottom").asNumber().toFloat() * scale; + + Rect rect = new Rect( + (int) left, + (int) top, + (int) (bitmap.getWidth() - right), + (int) (bitmap.getHeight() - bottom) + ); + NinePatchDrawable ninePatchDrawable = new NinePatchDrawable( getContext().getResources(), bitmap, diff --git a/doric-demo/assets/coupon_bg2.png b/doric-demo/assets/coupon_bg2.png new file mode 100644 index 00000000..fb6d1ebc Binary files /dev/null and b/doric-demo/assets/coupon_bg2.png differ diff --git a/doric-demo/assets/dididi.png b/doric-demo/assets/dididi.png new file mode 100644 index 00000000..34d29bb0 Binary files /dev/null and b/doric-demo/assets/dididi.png differ diff --git a/doric-demo/bundle/assets/coupon_bg2.png b/doric-demo/bundle/assets/coupon_bg2.png new file mode 100644 index 00000000..fb6d1ebc Binary files /dev/null and b/doric-demo/bundle/assets/coupon_bg2.png differ diff --git a/doric-demo/bundle/assets/dididi.png b/doric-demo/bundle/assets/dididi.png new file mode 100644 index 00000000..34d29bb0 Binary files /dev/null and b/doric-demo/bundle/assets/dididi.png differ diff --git a/doric-demo/src/ImageDemo.ts b/doric-demo/src/ImageDemo.ts index c3c948e8..8b38f500 100644 --- a/doric-demo/src/ImageDemo.ts +++ b/doric-demo/src/ImageDemo.ts @@ -158,7 +158,7 @@ class ImageDemo extends Panel { scaleType: ScaleType.ScaleAspectFill, layoutConfig: layoutConfig().just(), }), - label('StretchInset'), + label('StretchInset1'), image({ imageBase64: img_base64[1], height: 60, @@ -179,25 +179,51 @@ class ImageDemo extends Panel { bottom: 0 } }), - label('tileInset'), + + label('StretchInset 2'), image({ - imageBase64: img_base64[1], - height: 66, - width: 147, + image: new AssetsResource("coupon_bg2.png"), + height: 48, + width: 78, scaleType: ScaleType.ScaleAspectFill, layoutConfig: layoutConfig().just(), }), image({ - imageBase64: img_base64[1], - height: 66 * 2, - width: 147 * 2, - backgroundColor: Color.CYAN, + image: new AssetsResource("coupon_bg2.png"), + height: 48, + width: 78*3, + scaleType: ScaleType.ScaleToFill, + imageScale:1, + layoutConfig: layoutConfig().just(), + stretchInset: { + left: 0, + top: 0, + right: 76, + bottom: 0 + } + }), + + label('tileInset'), + image({ + image: new AssetsResource("dididi.png"), + height: 78, + width: 84, + backgroundColor: Color.BLACK, + scaleType: ScaleType.ScaleAspectFill, + layoutConfig: layoutConfig().just(), + }), + image({ + image: new AssetsResource("dididi.png"), + height: 78 * 1, + width: 84 * 3, + imageScale:1, + backgroundColor: Color.BLACK, scaleType: ScaleType.ScaleToFill, layoutConfig: layoutConfig().just(), tileInset: { left: 0, top: 0, - right: 83, + right: 0, bottom: 0 } }), @@ -242,4 +268,4 @@ class ImageDemo extends Panel { onDestroy() { modal(context).toast('onDestroy') } -} +} \ No newline at end of file