无法将图像合并到垂直对齐并共享该文件。在这种情况下,最后一个图像文件将仅添加到mergeImage的末尾。请参阅以下代码:
import 'package:image/image.dart' as im;
final path = (await getTemporaryDirectory()).path;
var i = 0;
List<String> paths = [];
await for (final page in Printing.raster(pdf, dpi: 72)) {
final png = await page.toPng();
final file = File('$path/page-${i.toString().padLeft(3, '0')}.png');
await file.writeAsBytes(png);
print('Saved to ${file.absolute.path}');
paths.add(file.absolute.path);
i++;
print('object');
}
int height = 0;
int width = im.decodeImage(File(paths.first).readAsBytesSync()).width;
for (var item in paths) {
final image = im.decodeImage(File(item).readAsBytesSync());
height += image.height + 10;
}
im.Image fullMergeImage;
int pos = 0;
for (var item in paths) {
print('object');
fullMergeImage = im.Image(width, height);
final image = im.decodeImage(File(item).readAsBytesSync());
im.copyInto(fullMergeImage, image, dstY: pos, blend: false);
pos += image.height + 10;
}
final documentDirectory = await getTemporaryDirectory();
final file = new File(documentDirectory.path + '.png');
file.writeAsBytesSync(im.encodeJpg(fullMergeImage));
await Share.shareFiles([file.absolute.path], text: 'Great picture');
2条答案
按热度按时间njthzxwz1#
fullMergeImage声明有问题。
yk9xbfzb2#