Flutter:合并两张图像并将其存储在本地存储中作为单一图像。

huangapple go评论99阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年1月6日 19:59:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611736.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定