'How do I convert SVG image into Bytes in dart and how to again decode that bytes List
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
