change px to proportion
This commit is contained in:
parent
36eaf35cd0
commit
4c18171a2b
@ -68,7 +68,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
|||||||
private String errorImage;
|
private String errorImage;
|
||||||
private int placeHolderColor = Color.TRANSPARENT;
|
private int placeHolderColor = Color.TRANSPARENT;
|
||||||
private int errorColor = Color.TRANSPARENT;
|
private int errorColor = Color.TRANSPARENT;
|
||||||
private Rect stretchInset = null;
|
private JSObject stretchInset = null;
|
||||||
|
|
||||||
public ImageNode(DoricContext doricContext) {
|
public ImageNode(DoricContext doricContext) {
|
||||||
super(doricContext);
|
super(doricContext);
|
||||||
@ -237,11 +237,23 @@ public class ImageNode extends ViewNode<ImageView> {
|
|||||||
Bitmap bitmap = ((BitmapDrawable) resource).getBitmap();
|
Bitmap bitmap = ((BitmapDrawable) resource).getBitmap();
|
||||||
|
|
||||||
if (stretchInset != null) {
|
if (stretchInset != null) {
|
||||||
|
float left = stretchInset.getProperty("left").asNumber().toFloat();
|
||||||
|
float top = stretchInset.getProperty("top").asNumber().toFloat();
|
||||||
|
float right = stretchInset.getProperty("right").asNumber().toFloat();
|
||||||
|
float bottom = stretchInset.getProperty("bottom").asNumber().toFloat();
|
||||||
|
|
||||||
|
Rect rect = new Rect(
|
||||||
|
(int) (bitmap.getWidth() * left),
|
||||||
|
(int) (bitmap.getHeight() * top),
|
||||||
|
(int) (bitmap.getWidth() * (1 - right)),
|
||||||
|
(int) (bitmap.getHeight() * (1 - bottom))
|
||||||
|
);
|
||||||
|
|
||||||
NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(
|
NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(
|
||||||
getContext().getResources(),
|
getContext().getResources(),
|
||||||
bitmap,
|
bitmap,
|
||||||
DoricUtils.getNinePatchChunk(stretchInset),
|
DoricUtils.getNinePatchChunk(rect),
|
||||||
stretchInset,
|
rect,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
super.setResource(ninePatchDrawable);
|
super.setResource(ninePatchDrawable);
|
||||||
@ -332,11 +344,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
|||||||
break;
|
break;
|
||||||
case "stretchInset":
|
case "stretchInset":
|
||||||
if (prop.isObject()) {
|
if (prop.isObject()) {
|
||||||
int left = prop.asObject().getProperty("left").asNumber().toInt();
|
stretchInset = prop.asObject();
|
||||||
int top = prop.asObject().getProperty("top").asNumber().toInt();
|
|
||||||
int right = prop.asObject().getProperty("right").asNumber().toInt();
|
|
||||||
int bottom = prop.asObject().getProperty("bottom").asNumber().toInt();
|
|
||||||
stretchInset = new Rect(left, top, right, bottom);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -119,9 +119,9 @@ class ImageDemo extends Panel {
|
|||||||
scaleType: ScaleType.ScaleToFill,
|
scaleType: ScaleType.ScaleToFill,
|
||||||
layoutConfig: layoutConfig().just(),
|
layoutConfig: layoutConfig().just(),
|
||||||
stretchInset: {
|
stretchInset: {
|
||||||
left: 125,
|
left: 0.85,
|
||||||
top: 0,
|
top: 0,
|
||||||
right: 22,
|
right: 0.149,
|
||||||
bottom: 0
|
bottom: 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -240,7 +240,7 @@ - (void)afterBlended:(NSDictionary *)props {
|
|||||||
CGFloat top = [self.stretchInsetDic[@"top"] floatValue];
|
CGFloat top = [self.stretchInsetDic[@"top"] floatValue];
|
||||||
CGFloat right = [self.stretchInsetDic[@"right"] floatValue];
|
CGFloat right = [self.stretchInsetDic[@"right"] floatValue];
|
||||||
CGFloat bottom = [self.stretchInsetDic[@"bottom"] floatValue];
|
CGFloat bottom = [self.stretchInsetDic[@"bottom"] floatValue];
|
||||||
UIImage *result = [self.view.image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch];
|
UIImage *result = [self.view.image resizableImageWithCapInsets:UIEdgeInsetsMake(top * self.view.image.size.height, left * self.view.image.size.width, bottom * self.view.image.size.height, right * self.view.image.size.width) resizingMode:UIImageResizingModeStretch];
|
||||||
self.view.image = result;
|
self.view.image = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user