Commit 004a3f9382aa575573574727a7f9b1adb9980c21

Authored by wdn127929
1 parent 9e0dbd43

封面图蒙版iOS和安卓不一样,iOS需要多加一层且第一层画笔不能是透明色

Showing 1 changed file with 146 additions and 8 deletions
... ... @@ -2099,12 +2099,133 @@ class Utils {
stream.addListener(ImageStreamListener(listener));
return completer.future;
}
// static Future<ui.Image> getImage(String asset) async {
// ByteData data = await rootBundle.load(asset);
// Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List());
// FrameInfo fi = await codec.getNextFrame();
// return fi.image;
// }
// static Future<Uint8List> canvas(
// context, String _thumbnail, String month, String week) async {
// var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
// var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
// var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
// print(images);
// // Paint _linePaint = new Paint()
// // ..color = Colors.blue
// // ..style = PaintingStyle.fill
// // ..isAntiAlias = true
// // ..strokeCap = StrokeCap.round
// // ..strokeWidth = 500;
// // Paint selfPaint = Paint()
// // ..color = Colors.red
// // ..style = PaintingStyle.fill
// // ..isAntiAlias = true
// // ..strokeCap = StrokeCap.butt
// // ..strokeWidth = 2;
// final paint = Paint()
// // ..color = Colors.red
// // ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
// ..style = PaintingStyle.fill;
// // 绘制一个矩形作为蒙版
// // canvas.drawRect(Rect.fromLTRB(10, 10, 80, 80), paint);
// // // 应用蒙版后,再绘制其他图形
// // paint.maskFilter = null;
// // canvas.drawCircle(Offset(60, 60), 30, paint);
// // canvas.drawRect(Rect.fromLTWH(0, 0, 500, 400), paint);
// // canvas.drawImage(images, Offset(0, 0), paint);
// // 定义源矩形,通常是图像的全部
// final Rect source = Rect.fromLTWH(
// 0.0, 0.0, images.width.toDouble(), images.height.toDouble());
// // 定义目标矩形,即画布的大小
// final Rect destination = Rect.fromLTWH(0.0, 0.0, 500, 400);
// // 绘制图像
// canvas.drawImageRect(images, source, destination, paint);
// final paint1 = Paint()
// ..color = Colors.black.withOpacity(0.4)
// ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
// ..style = PaintingStyle.fill;
// // 绘制一个矩形作为蒙版
// canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
// // 在画布上绘制图片,使用BoxFit来适配画布大小
// // canvas.drawImageRect(
// // images,
// // Rect.fromLTWH(0, 0, images.width.toDouble(), images.height.toDouble()),
// // Rect.fromLTWH(0, 0, images.width.toDouble(), images.height.toDouble()),
// // paint);
// // 绘制文字
// ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
// textAlign: TextAlign.center,
// fontWeight: FontWeight.normal,
// fontStyle: FontStyle.normal,
// // :MyColours.color_000000,
// fontSize: 26));
// pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 26));
// pb2.addText(
// '${Provider.of<UserModel>(context, listen: false).user.sellername}');
// // 设置文本的宽度约束
// ParagraphConstraints pc2 = ui.ParagraphConstraints(width: 500);
// ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
// canvas.drawParagraph(paragraph2, Offset(10, 40));
// // 绘制文字
// ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
// textAlign: TextAlign.center,
// fontWeight: FontWeight.bold,
// fontStyle: FontStyle.normal,
// // :MyColours.color_000000,
// fontSize: 48));
// pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 48));
// pb.addText(month);
// // 设置文本的宽度约束
// ParagraphConstraints pc = ui.ParagraphConstraints(width: 500);
// ui.Paragraph paragraph = pb.build()..layout(pc);
// canvas.drawParagraph(paragraph, Offset(10, 150));
// // 绘制文字
// ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
// textAlign: TextAlign.center,
// fontWeight: FontWeight.bold,
// fontStyle: FontStyle.normal,
// // :MyColours.color_000000,
// fontSize: 42));
// pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 42));
// pb3.addText(week);
// // 设置文本的宽度约束
// ParagraphConstraints pc3 = ui.ParagraphConstraints(width: 500);
// ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
// canvas.drawParagraph(paragraph3, Offset(10, 230));
// //下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
// var picture =
// await pictureRecorder.endRecording().toImage(500, 400); //设置生成图片的宽和高
// var pngImageBytes =
// await picture.toByteData(format: ui.ImageByteFormat.png);
// // var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
// Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
// print(pngBytes); //pngBytes可以放在Image.memory()中预览
// // setState(() {
// // imageMemory = pngBytes;
// // Uint8List result = await resizeImage(pngBytes); //重置图片尺寸
// Uint8List result = await testFromFileComporessList(context, pngBytes);
// return result;
// }
static Future<Uint8List> canvas(
context, String _thumbnail, String month, String week) async {
... ... @@ -2124,20 +2245,37 @@ class Utils {
// ..isAntiAlias = true
// ..strokeCap = StrokeCap.butt
// ..strokeWidth = 2;
final paint = Paint()
..color = Color.fromRGBO(81, 81, 81, 0.4)
Paint paint = Paint()
..color = Color.fromRGBO(81, 81, 81, 0.6)
..style = PaintingStyle.fill;
if (Platform.isIOS) {
paint = Paint()
// ..color = Colors.red
// ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
..style = PaintingStyle.fill;
}
// canvas.drawRect(Rect.fromLTWH(0, 0, 500, 400), paint);
// canvas.drawImage(images, Offset(0, 0), paint);
// 定义源矩形,通常是图像的全部
final Rect source = Rect.fromLTWH(0.0, 0.0, images.width.toDouble(), images.height.toDouble());
// 定义目标矩形,即画布的大小
final Rect destination = Rect.fromLTWH(0.0, 0.0, 500, 400);
// 绘制图像
canvas.drawImageRect(images, source, destination, paint);
// 定义源矩形,通常是图像的全部
final Rect source = Rect.fromLTWH(
0.0, 0.0, images.width.toDouble(), images.height.toDouble());
// 定义目标矩形,即画布的大小
final Rect destination = Rect.fromLTWH(0.0, 0.0, 500, 400);
// 绘制图像
canvas.drawImageRect(images, source, destination, paint);
if (Platform.isIOS) {
final paint1 = Paint()
..color = Colors.black.withOpacity(0.6)
..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
..style = PaintingStyle.fill;
// 绘制一个矩形作为蒙版
canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
}
// 在画布上绘制图片,使用BoxFit来适配画布大小
// canvas.drawImageRect(
... ...