英文:
Flutter: Merge two images and store it in local storage as a single image
问题
我想合并两张图像并显示和存储它们为一张单独的图像。
英文:
I want to merge two images and show & store them as a single image.
答案1
得分: 20
找到答案,感谢这个出色的库 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));
英文:
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));
答案2
得分: 0
你可以尝试使用这个包并像往常一样保存生成的图像:
https://pub.dev/packages/merge_images
英文:
You can try giving this package a shot and save the resulting Image as usual
https://pub.dev/packages/merge_images
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论