Image 有没有办法将动态加载的图像文件合并到Flatter中的一个图像文件?
有没有办法将动态加载的图像文件合并到Flatter中的一个图像文件 我已经添加了图像。 我需要将加载的图像合并到一个图像中。下面给出了我使用的代码Image 有没有办法将动态加载的图像文件合并到Flatter中的一个图像文件?,image,flutter,merge,flutter-layout,Image,Flutter,Merge,Flutter Layout,有没有办法将动态加载的图像文件合并到Flatter中的一个图像文件 我已经添加了图像。 我需要将加载的图像合并到一个图像中。下面给出了我使用的代码 import 'dart:io'; import 'package:flutter/material.dart'; import 'package:image/image.dart' as immg; import 'package:image_cropper/image_cropper.dart'; import 'package:image_p
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image/image.dart' as immg;
import 'package:image_cropper/image_cropper.dart';
import 'package:image_picker/image_picker.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:merge_images/merge_images.dart';
class SingleImageUpload extends StatefulWidget {
@override
_SingleImageUploadState createState() {
return _SingleImageUploadState();
}
}
class _SingleImageUploadState extends State<SingleImageUpload> {
List<Object> images = List<Object>();
List<File> imgList = List<File>();
List<Image> listimg = List<Image>();
File _selectedFile;
bool _inProcess = false;
Map data = {};
Readerservice _readerservice;
@override
void initState() {
// TODO: implement initState
super.initState();
setState(() {
images.add("Add Image");
images.add("Add Image");
images.add("Add Image");
images.add("Add Image");
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
home: new Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: Padding(
padding: EdgeInsets.only(left: 12),
child: IconButton(
icon: Icon(Icons.arrow_back_ios,
color: Colors.black,
size: 30,),
onPressed: () {
Navigator.pushNamed(context, '/Mainpage');
},
),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget>[
Text('Basic AppBar'),
]
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.more_vert,
color: Colors.black,
size: 30,),
onPressed: () {
print('Click start');
},
),
],
),
body:
SizedBox(height: 40),
Expanded(
child: buildGridView(),
),
RaisedButton(
textColor: Colors.white,
color: Colors.orange,
child: Text("Finish",
style: TextStyle(fontSize: 15),),
onPressed: () {
pasimage();
},
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0),
),
),
],
),
),
);
}
Widget buildGridView() {
return GridView.count(
shrinkWrap: true,
crossAxisCount: 3,
childAspectRatio: 1,
children: List.generate(images.length, (index) {
if (images[index] is ImageUploadModel) {
ImageUploadModel uploadModel = images[index];
return Card(
clipBehavior: Clip.antiAlias,
child: Stack(
children: <Widget>[
Image.file(
uploadModel.imageFile,
width: 300,
height: 300,
),
Positioned(
right: 5,
top: 5,
child: InkWell(
child: Icon(
Icons.remove_circle,
size: 20,
color: Colors.red,
),
onTap: () {
setState(() {
images.replaceRange(index, index + 1, ['Add Image']);
});
},
),
),
],
),
);
} else {
return Card(
child: IconButton(
icon: Icon(Icons.add),
onPressed: () {
//popup
showDialog(
context: context,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
elevation: 16,
child: Container(
height: 180.0,
width: 330.0,
child: ListView(
children: <Widget>[
SizedBox(height: 20),
//Center(
Padding(
padding: const EdgeInsets.only(left: 15.0),
child: Text(
"Add a Receipt",
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 24,
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
// ),
SizedBox(height: 20),
FlatButton(
child: Text(
'Take a photo..',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 20),
),
onPressed: () {
_onAddImageClick(index,ImageSource.camera);
Navigator.of(context).pop();
// picker.getImage(ImageSource.camera);
},
textColor: Colors.black,
),
FlatButton(
child: Text(
'Choose from Library..',
style: TextStyle(fontSize: 20),
textAlign: TextAlign.left,
),
onPressed: () {
_onAddImageClick(index,ImageSource.gallery);
Navigator.of(context).pop();
},
textColor: Colors.black,
),
],
),
),
);
},
);
//pop ends
//_onAddImageClick(index);
},
),
);
}
}),
);
}
Future _onAddImageClick(int index, ImageSource source ) async {
setState(() {
_inProcess = true;
});
File image = await ImagePicker.pickImage(source: source);
if(image != null){
File cropped = await ImageCropper.cropImage(
sourcePath: image.path,
maxWidth: 1080,
maxHeight: 1080,
compressFormat: ImageCompressFormat.jpg,
androidUiSettings: AndroidUiSettings(
toolbarColor: Colors.black,
toolbarWidgetColor: Colors.white,
//toolbarTitle: "RPS Cropper",
statusBarColor: Colors.deepOrange.shade900,
backgroundColor: Colors.black,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false
),
iosUiSettings: IOSUiSettings(
minimumAspectRatio: 1.0,
)
);
this.setState((){
_selectedFile = cropped ;
_inProcess = false;
});
} else {
this.setState((){
_inProcess = false;
});
}
getFileImage(index);
}
void getFileImage(int index) async {
// var dir = await path_provider.getTemporaryDirectory();
setState(() {
ImageUploadModel imageUpload = new ImageUploadModel();
imageUpload.isUploaded = false;
imageUpload.uploading = false;
imageUpload.imageFile = _selectedFile ;
imageUpload.imageUrl = '';
imgList.add(imageUpload.imageFile);
images.replaceRange(index, index + 1, [imageUpload]);
print(imgList);
});
}
void pasimage(){
for(var i=0;i<imgList.length;i++){
final imaes = immg.decodeImage(imgList[i].readAsBytesSync()) as Image;
listimg.add(imaes);
}
Navigator.pushReplacementNamed(context, '/crop',arguments: {
'imageList':ImagesMerge(
listimg,///required,images list
direction: Axis.vertical,///direction
backgroundColor: Colors.black26,///background color
fit: false,///scale image to fit others
//controller: captureController,///controller to get screen shot
),
});
}
}
class ImageUploadModel {
bool isUploaded;
bool uploading;
File imageFile;
String imageUrl;
ImageUploadModel({
this.isUploaded,
this.uploading,
this.imageFile,
this.imageUrl,
});
}
导入“dart:io”;
进口“包装:颤振/材料.省道”;
将“package:image/image.dart”作为immg导入;
导入“package:image_cropper/image_cropper.dart”;
导入“包:image_picker/image_picker.dart”;
将“package:http/http.dart”导入为http;
导入“dart:convert”;
导入“package:merge_images/merge_images.dart”;
类SingleImageUpload扩展了StatefulWidget{
@凌驾
_SingleImageUploadState createState(){
返回_SingleImageUploadState();
}
}
类_SingleImageUploadState扩展状态{
列表图像=列表();
List imgList=List();
List listimg=List();
文件\u选择的文件;
bool\u inProcess=false;
地图数据={};
读者服务(Readerservice);;
@凌驾
void initState(){
//TODO:实现initState
super.initState();
设置状态(){
图像。添加(“添加图像”);
图像。添加(“添加图像”);
图像。添加(“添加图像”);
图像。添加(“添加图像”);
});
}
@凌驾
小部件构建(构建上下文){
返回新材料PP(
debugShowCheckedModeBanner:false,
家:新脚手架(
appBar:appBar(
背景颜色:Colors.white,
前导:填充(
填充:仅限边缘设置(左:12),
孩子:我的钮扣(
图标:图标(Icons.arrow\u back\u ios、,
颜色:颜色,黑色,
尺码:30,),,
已按下:(){
Navigator.pushNamed(上下文“/Mainpage”);
},
),
),
标题:世界其他地区(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
文本(“基本应用程序栏”),
]
),
行动:[
图标按钮(
图标:图标(Icons.more_vert,
颜色:颜色,黑色,
尺码:30,),,
已按下:(){
打印(“单击开始”);
},
),
],
),
正文:
尺寸箱(高度:40),
扩大(
子级:buildGridView(),
),
升起的按钮(
textColor:Colors.white,
颜色:颜色。橙色,
子项:文本(“完成”,
样式:TextStyle(字体大小:15),),
已按下:(){
pasimage();
},
形状:新的RoundedRectangleBorder(
边界半径:新边界半径。圆形(8.0),
),
),
],
),
),
);
}
Widget buildGridView(){
返回GridView.count(
收缩膜:对,
交叉轴计数:3,
儿童方面:1,
子项:List.generate(images.length,(index){
if(图像[索引]为ImageUploadModel){
ImageUploadModel uploadModel=图像[索引];
回程卡(
clipBehavior:Clip.antiAlias,
子:堆栈(
儿童:[
Image.file(
uploadModel.imageFile,
宽度:300,
身高:300,
),
定位(
右:5,,
前五名,
孩子:InkWell(
子:图标(
图标。删除“”圆,
尺码:20,
颜色:颜色,红色,
),
onTap:(){
设置状态(){
replaceRange(索引,索引+1,['addimage']);
});
},
),
),
],
),
);
}否则{
回程卡(
孩子:我的钮扣(
图标:图标(Icons.add),
已按下:(){
//弹出窗口
显示对话框(
上下文:上下文,
生成器:(上下文){
返回对话框(
形状:圆形矩形边框(
边界半径:边界半径。圆形(10)),
海拔:16,
子:容器(
高度:180.0,
宽度:330.0,
子:ListView(
儿童:[
尺寸箱(高度:20),
//居中(
填充物(
填充:仅限常量边集(左:15.0),
子:文本(
“添加收据”,
textAlign:textAlign.left,
样式:TextStyle(
尺寸:24,
颜色:颜色,黑色,
fontWeight:fontWeight.bold),
),
),
// ),
尺寸箱(高度:20),
扁平按钮(
子:文本(
“拍照……”,
textAlign:textAlign.left,
样式:TextStyle(字体大小:20),
),
已按下:(){
_onAddImageClick(索引,ImageSource.camera);
Navigator.of(context.pop();
//picker.getImage(ImageSource.camera);
},
textColor:Colors.black,
),
import 'dart:ui' as ui;
List<ui.Image> listimg = List<ui.Image>();
...
void pasimage(){
for(var i=0;i<imgList.length;i++){
final imaes = await ImagesMergeHelper.loadImageFromFile(imgList[i]) as ui.Image;
listimg.add(imaes);
}
Navigator.pushReplacementNamed(context, '/crop',arguments: {
'imageList':ImagesMerge(
listimg,///required,images list
direction: Axis.vertical,///direction
backgroundColor: Colors.black26,///background color
fit: false,///scale image to fit others
//controller: captureController,///controller to get screen shot
),
});
}