浏览代码

fix image box fit

/main
gewentao 6 年前
当前提交
cd9dc1c3
共有 3 个文件被更改,包括 19 次插入10 次删除
  1. 9
      Assets/UIWidgets/Tests/Widgets.cs
  2. 9
      Assets/UIWidgets/painting/box_fit.cs
  3. 11
      Assets/UIWidgets/ui/painting/canvas_impl.cs

9
Assets/UIWidgets/Tests/Widgets.cs


height: 450,
color: CLColors.white,
child: widgets.Image.network(
"https://d2ujflorbtfzji.cloudfront.net/banner/38942865-28db-482b-80c5-17809473f3c6.jpg",
"https://d2ujflorbtfzji.cloudfront.net/banner/5c57178c-4be6-4903-953b-85125bfb7154.jpg",
fit: BoxFit.cover
)
);

public override Widget build(BuildContext context) {
var card = new Container(
margin: EdgeInsets.only(right: 45),
color: CLColors.white,
color: CLColors.white,
decoration: new BoxDecoration(
color: CLColors.white,
borderRadius: BorderRadius.only(topLeft: 3, topRight: 3)
),
width: 200,
height: 124,
child: widgets.Image.network(

),
new Container(
color: CLColors.white,
width: 200,
height: 86,
padding: EdgeInsets.fromLTRB(14, 12, 14, 8),

9
Assets/UIWidgets/painting/box_fit.cs


case BoxFit.cover:
if (outputSize.width / outputSize.height > inputSize.width / inputSize.height) {
sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width);
} else {
sourceSize = new Size(inputSize.height * outputSize.width / outputSize.height, inputSize.height);
else {
sourceSize = new Size(inputSize.height * outputSize.width / outputSize.height,
inputSize.height);
}
break;
break;
case BoxFit.fitWidth:
sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width);
destinationSize = new Size(outputSize.width,

11
Assets/UIWidgets/ui/painting/canvas_impl.cs


public void drawImageRect(Rect src, Rect dst, Paint paint, Image image) {
if (image != null && image.texture != null) {
Graphics.DrawTexture(dst.toRect(), image.texture);
// convert src rect to Unity rect in normalized coordinates with (0,0) in the bottom-left corner.
var textureHeight = image.texture.height;
var textureWidth = image.texture.width;
var srcRect = new UnityEngine.Rect(
(float) (src.left / textureWidth),
(float) ((textureHeight - src.bottom) / textureHeight),
(float) (src.width / textureWidth),
(float) (src.height / textureHeight)
);
Graphics.DrawTexture(dst.toRect(), image.texture, srcRect, 0, 0 ,0 ,0);
}
}

正在加载...
取消
保存