Skip to content

Commit e63fcb7

Browse files
committed
添加注释
1 parent 83e4c36 commit e63fcb7

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

lib/DrawImageUtils.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class DrawImageUtils {
1313
static Future<flutterUi.Image> drawFrameImage(
1414
String originImageUrl, String frameImageUrl) {
1515
Completer<flutterUi.Image> completer = new Completer<flutterUi.Image>();
16+
//加载图片
1617
Future.wait([
1718
OriginImage.getInstance().loadImage(originImageUrl),
1819
ImageLoader.load(frameImageUrl)
@@ -45,6 +46,8 @@ class DrawImageUtils {
4546
originHeight),
4647
Rect.fromLTWH(0, 0, width.toDouble(), height.toDouble()),
4748
paint);
49+
50+
//裁剪图片
4851
paint.blendMode = BlendMode.dstIn;
4952
canvas.drawImage(result[1], Offset(0, 0), paint);
5053
recorder.endRecording().toImage(width, height).then((image) {
@@ -62,6 +65,7 @@ class DrawImageUtils {
6265
Completer<flutterUi.Image> completer = new Completer<flutterUi.Image>();
6366
Future.wait([
6467
ImageLoader.load(maskImage),
68+
//获取裁剪图片
6569
drawFrameImage(originImageUrl, frameImageUrl)
6670
]).then((result) {
6771
Paint paint = new Paint();
@@ -71,13 +75,16 @@ class DrawImageUtils {
7175
int width = result[0].width;
7276
int height = result[0].height;
7377

78+
//合成
7479
canvas.drawImage(result[1], offset, paint);
7580
canvas.drawImageRect(
7681
result[0],
7782
Rect.fromLTWH(
7883
0, 0, result[0].width.toDouble(), result[0].height.toDouble()),
7984
Rect.fromLTWH(0, 0, width.toDouble(), height.toDouble()),
8085
paint);
86+
87+
//生成图片
8188
recorder.endRecording().toImage(width, height).then((image) {
8289
completer.complete(image);
8390
});

lib/DrawPIPWidget.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class DrawPIPState extends State<DrawPIPWidget> {
3434
height: _width,
3535
child: new Stack(
3636
children: <Widget>[
37-
getBackgroundImage(),
37+
getBackgroundImage(), //底部高斯模糊图片
38+
//合成后的效果图片,使用CustomPaint 绘制出来
3839
CustomPaint(
3940
painter: DrawPainter(widget._image),
4041
size: Size(_width, _width)),

lib/PreviewImagePage.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PreviewImageWidget extends StatefulWidget {
2727
}
2828

2929
class PreviewImageState extends State<PreviewImageWidget> {
30-
final GlobalKey globalKey = new GlobalKey();
30+
final GlobalKey pipCaptureKey = new GlobalKey();
3131

3232
List<String> _listImageIcon = [];
3333
List<Offset> _imageOffset = [];
@@ -82,15 +82,15 @@ class PreviewImageState extends State<PreviewImageWidget> {
8282
getBottomListView()
8383
]))),
8484
floatingActionButton: FloatingActionButton(
85-
onPressed: _capturePng,
85+
onPressed: _captureImage,
8686
tooltip: 'save',
8787
child: Icon(Icons.save),
8888
));
8989
}
9090

9191
Widget getPIPImageWidget() {
9292
return RepaintBoundary(
93-
key: globalKey,
93+
key: pipCaptureKey,
9494
child: new Center(child: new DrawPIPWidget(_originImage, _image)),
9595
);
9696
}
@@ -138,9 +138,9 @@ class PreviewImageState extends State<PreviewImageWidget> {
138138
padding: EdgeInsets.all(20), height: 140, child: listView);
139139
}
140140

141-
Future<void> _capturePng() async {
141+
Future<void> _captureImage() async {
142142
RenderRepaintBoundary boundary =
143-
globalKey.currentContext.findRenderObject();
143+
pipCaptureKey.currentContext.findRenderObject();
144144
var image = await boundary.toImage();
145145
ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
146146
Uint8List pngBytes = byteData.buffer.asUint8List();
@@ -157,17 +157,17 @@ class PreviewImageState extends State<PreviewImageWidget> {
157157
barrierDismissible: false,
158158
builder: (BuildContext context) {
159159
return AlertDialog(
160-
title: Text('Save success'),
160+
title: Text('PIP Path'),
161161
content: SingleChildScrollView(
162162
child: ListBody(
163163
children: <Widget>[
164-
Text('Image is save in ${path}'),
164+
Text('Image is save in $path'),
165165
],
166166
),
167167
),
168168
actions: <Widget>[
169169
FlatButton(
170-
child: Text('exit'),
170+
child: Text('退出'),
171171
onPressed: () {
172172
Navigator.of(context).pop();
173173
},

0 commit comments

Comments
 (0)