获取图片资源
//方法1:获取网络图片 返回ui.Image
Future
绘制
_drawImage(Canvas canvas, ui.Image image) async {
final paint = Paint()
..color = Colors.white
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round;
final rect = Rect.fromLTWH(0, 4, 16, 16);
/// 绘制圆角边框
canvas.drawRRect(
RRect.fromRectAndRadius(rect, Radius.circular(4.0)), paint);
/// 绘制圆角图片
if (image != null) {
canvas.drawRRect(
RRect.fromRectAndRadius(
Rect.fromLTWH(1, 5, 14, 14),
Radius.circular(4.0)),
Paint()
..shader = ImageShader(
image,
TileMode.decal,
TileMode.decal,
Float64List.fromList(
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),
),
);
} else {
canvas.drawRRect(
RRect.fromRectAndRadius(
Rect.fromLTWH(1, 5, 14, 14),
Radius.circular(4.0)),
Paint()..color = Colors.grey.withOpacity(0.5),
);
}
}