• Flutter Image(图片)


    https://www.jianshu.com/p/c4463d1b277f

    868

    Image是一个用于展示图片的组件。支持 JPEG、PNG、GIF、Animated GIF、WebP、Animated WebP、BMP 和 WBMP 等格式。

    Image 有许多的静态函数:

    • new Image.asset - 用于从资源目录的显示图片。
    • new Image.network - 用于从网络上显示图片。
    • new Image.file - 用于从文件里显示图片。
    • new Image.memory - 用于从内存里(Uint8List)显示图片。
    // 资源图片
    new Image.asset('imgs/logo.jpeg'),
    //网络图片
    new Image.network(
        'https://flutter.io/images/homepage/header-illustration.png'),
    // 本地文件图片
    new Image.file(new File("/Users/gs/Downloads/1.jpeg")),
    // Uint8List图片
    new Image.memory(bytes),
    //使用ImageProvider加载图片
    new Image(image: new NetworkImage("https://flutter.io/images/homepage/screenshot-2.png"))
    

    Image 有以下常用属性:

    • alignment → AlignmentGeometry - 图像边界内对齐图像。
    • centerSlice → Rect - 九片图像的中心切片。
    • color → Color - 该颜色与每个图像像素混合colorBlendMode。
    • colorBlendMode → BlendMode - 用于 color 与此图像结合使用。
    • fit → BoxFit - 图像在布局中分配的空间。
    • gaplessPlayback → bool - 当图像提供者发生变化时,是继续显示旧图像(true)还是暂时不显示(false)。
    • image → ImageProvider - 要显示的图像。
    • matchTextDirection → bool - 是否在图像的方向上绘制图像 TextDirection。
    • repeat → ImageRepeat - 未充分容器时,是否重复图片。
    • height → double - 图像的高度。
    • width → double - 图像的宽度。

    圆角图片

    Image 是不支持圆角和阴影的,目前可以通过使用 CircleAvatar 和 Container 实现。

    var img = 'https://b-ssl.duitang.com/uploads/item/' +
            '201602/15/20160215235057_EU3tS.thumb.700_0.jpeg';
    
    new CircleAvatar(
        backgroundImage: new NetworkImage(url),
        radius: 100.0,      // --> 半径越大,图片越大
    ),
    
     

    使用 Container 实现,其原理是把图片放在 decoration 里,而不是 child 里,因为把图片放在 child 里并设置 borderRadius 时会出现一个图片穿透的问题,Container 还没有 overflow 属性。

    new Container(
        width: 200.0,
        height: 200.0,
        margin: const EdgeInsets.all(20.0),
        decoration: new BoxDecoration(
            color: Colors.white,
            image: new DecorationImage(image: new NetworkImage(this.imgsrc), fit: BoxFit.cover),
            shape: BoxShape.circle,
        ),
    ),
    

    上面实现的都是一个圆形图片,下面的实现一个真正的圆角图片。

    new Container(
        width: 200.0,
        height: 200.0,
        margin: const EdgeInsets.all(20.0),
        decoration: new BoxDecoration(
            color: Colors.white,
            image: new DecorationImage(image: new NetworkImage(this.imgsrc), fit: BoxFit.cover),
            shape: BoxShape.rectangle,              // <-- 这里需要设置为 rectangle
            borderRadius: new BorderRadius.all(
                const Radius.circular(20.0),        // <-- rectangle 时,BorderRadius 才有效
            ),
        ),
    ),
    
     
  • 相关阅读:
    计算机操作系统实验之_进程观测_实验报告
    KVO(NSKeyValueObserving 键 值编码)与KVC(NSKeyValueCoding 键值观察机制)详解
    用arrayWithObject:初始化,参数为空数组NSArray时出现的异常
    用QtCreator实现可扩展对话框实验
    xcode4 设置调试错误信息小结
    从“Qt信号槽机制”到”iOS(MVC)中的Target——Action机制”
    Qt源码分析之信号和槽机制
    objectivec 学习之NSMutableDictionary介绍
    iOS面试题汇总 (1)
    报告论文:关于一个小型学生信息管理系统研究
  • 原文地址:https://www.cnblogs.com/sundaysme/p/12560721.html
Copyright © 2020-2023  润新知