Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Merge two images and store it in local storage as a single image

Tags:

flutter

dart

I want to merge two images and show & store them as a single image.

like image 438
Jagath Ratchagan Avatar asked Jan 06 '20 11:01

Jagath Ratchagan


1 Answers

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));
like image 171
Jagath Ratchagan Avatar answered Nov 16 '22 04:11

Jagath Ratchagan