Reputation: 545
I am trying to merge two images and store them as a single image in local storage in Flutter
Upvotes: 17
Views: 14264
Reputation: 108
In the latest version if image package..
copyInto(mergedImage, image2, dstx = image1.width, blend = false);
is replaced with
compositeImage(mergedImage, image2, dstX: image1.width, // and other properties);
Upvotes: 3
Reputation: 2501
By using: merge_images: ^2.0.0-nullsafety
import 'dart:ui' as ui;
import 'package:merge_images/merge_images.dart';
Future<void> _mergeImages() async {
final imageList = await _createImageList([_frontImage, _backImage]);
ui.Image image = await ImagesMergeHelper.margeImages(imageList,
fit: true, direction: Axis.vertical, backgroundColor: Colors.white);
}
Upvotes: 0
Reputation: 2763
You can try giving this package a shot and save the resulting Image as usual https://pub.dev/packages/merge_images
Upvotes: 1
Reputation: 545
Found the answer, Thanks to this awesome library https://pub.dev/packages/image
final image1 = decodeImage(File('imageA.jpg').readAsBytesSync());
final image2 = decodeImage(File('imageB.jpg').readAsBytesSync());
final mergedImage = Image(image1.width + image2.width, max(image1.height, image2.height));
copyInto(mergedImage, image1, blend = false);
copyInto(mergedImage, image2, dstx = image1.width, blend = false);
final documentDirectory = await getApplicationDocumentsDirectory();
final file = new File(join(documentDirectory.path, "merged_image.jpg"));
file.writeAsBytesSync(encodeJpg(mergedImage));
Upvotes: 24