借助BlendMode属性可以处理图片的色值,有很多混合方式,官方文档:
https://api.flutter.dev/flutter/dart-ui/BlendMode-class.html
这里只说图片变黑白
方式一,直接设置image里的color和colorBlendMode属性:
Image.asset(
'img.png',
fit: BoxFit.cover,
color: Colors.black,
colorBlendMode: BlendMode.color,
)
方式二,通过ShaderMask设置blendMode:
ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(colors: [Colors.black, Colors.white]).createShader(bounds);
},
blendMode: BlendMode.color,
child: Image.asset(
'img.png',
fit: BoxFit.cover,
),
)
网友评论