如何将SVG图像转换为DART中的字节以及如何再次解码该字节列表

发布于 2025-01-23 17:02:15 字数 2029 浏览 2 评论 0原文

最终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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文