如何将SVG图像转换为DART中的字节以及如何再次解码该字节列表
最终watermarkbytes =(等待rootbundle.load(svg image))。buffer.asuint8list();
同样,我需要将这些WaterMarkBytes转换为图像数据类型。
_applyWaterMark({watermarkImage,lookbookImageUrl}) async{
final watermarkBytes = (await rootBundle.load(watermarkImage)) .buffer.asUint8List();
var img = await rootBundle.load(watermarkImage);
var decodedImage = await decodeImageFromList(img.buffer.asUint8List());
var watermarkRatio = decodedImage.width / decodedImage.height;
Image image = Image.network(lookbookImageUrl); // to get heigth and width of imageurl
ImageInfo info = await getImageInfo(image);
Uint8List? imgData = await Matting.getImageData(lookbookImageUrl);
final bytes = imgData;
/// [distY] is the vertical gap between the lookbook image edges and watermark edges;
/// [distX] is the horizontal gap between the lookbook image edges and watermark edges;
int distY = 0, distX = 0;
/// setting [distX], [distY] values based on the min. values of lookbook image's width and height;
if(info.image.width < info.image.height){
distY = info.image.height - decodedImage.height - ((2/100)*info.image.width).toInt();
distX = info.image.width - decodedImage.width - ((2/100)*info.image.width).toInt();
}
else {
distY = distX = info.image.height - decodedImage.height - ((2/100)*info.image.height).toInt();
distX = distX = info.image.width - decodedImage.width - ((2/100)*info.image.height).toInt();
}
var watermarkedImg = await image_watermark.addImageWatermark(imgData!, watermarkBytes,
imgHeight: (((decodedImage.width/watermarkRatio)/100)*info.image.height).toInt(), imgWidth: ((25/100)*info.image.width).toInt(),
dstY: distY, dstX: distX
);
return watermarkedImg;
}
// invoking a function
var afterWaterMarkedImage = await _applyWaterMark(watermarkImage: 'assets/images/imgLookbookWatermark.svg',lookbookImageUrl: imageurl); // imageurl is getting from API
final watermarkBytes = (await rootBundle.load(SVG Image)).buffer.asUint8List();
Again, I need to convert these watermarkBytes to Image Data Type.
_applyWaterMark({watermarkImage,lookbookImageUrl}) async{
final watermarkBytes = (await rootBundle.load(watermarkImage)) .buffer.asUint8List();
var img = await rootBundle.load(watermarkImage);
var decodedImage = await decodeImageFromList(img.buffer.asUint8List());
var watermarkRatio = decodedImage.width / decodedImage.height;
Image image = Image.network(lookbookImageUrl); // to get heigth and width of imageurl
ImageInfo info = await getImageInfo(image);
Uint8List? imgData = await Matting.getImageData(lookbookImageUrl);
final bytes = imgData;
/// [distY] is the vertical gap between the lookbook image edges and watermark edges;
/// [distX] is the horizontal gap between the lookbook image edges and watermark edges;
int distY = 0, distX = 0;
/// setting [distX], [distY] values based on the min. values of lookbook image's width and height;
if(info.image.width < info.image.height){
distY = info.image.height - decodedImage.height - ((2/100)*info.image.width).toInt();
distX = info.image.width - decodedImage.width - ((2/100)*info.image.width).toInt();
}
else {
distY = distX = info.image.height - decodedImage.height - ((2/100)*info.image.height).toInt();
distX = distX = info.image.width - decodedImage.width - ((2/100)*info.image.height).toInt();
}
var watermarkedImg = await image_watermark.addImageWatermark(imgData!, watermarkBytes,
imgHeight: (((decodedImage.width/watermarkRatio)/100)*info.image.height).toInt(), imgWidth: ((25/100)*info.image.width).toInt(),
dstY: distY, dstX: distX
);
return watermarkedImg;
}
// invoking a function
var afterWaterMarkedImage = await _applyWaterMark(watermarkImage: 'assets/images/imgLookbookWatermark.svg',lookbookImageUrl: imageurl); // imageurl is getting from API
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论