marcglasberg / image_pixels

Flutter Package: Lets you extend the background color of an image, or else build any widget that depends on the image width/height, and the color of its pixels.
MIT License
24 stars 5 forks source link

Using SVG images #12

Open luuquangxinhzaiii opened 10 months ago

luuquangxinhzaiii commented 10 months ago

Hi @marcglasberg , First of all, thanks for the amazing package, it's helped me a lot. I can use img.pixelColorAt() to get color from 1 point in the image But now I must use svg image as my input and it doesn't work

    Widget flutter = SvgPicture.asset(AssetHelper.gioviet); //this is svg image link
    ImageProvider flutterImageProvider = flutter as ImageProvider;
    Offset localPosition = const Offset(10, 10);
    return ImagePixels(
      imageProvider: flutterImageProvider,
      builder: (BuildContext context, ImgDetails img) {
        var color = img.pixelColorAt!(
          localPosition.dx.toInt(),
          localPosition.dy.toInt(),
        );
        Brightness brightness = ThemeData.estimateBrightnessForColor(color);
        return SizedBox(
          width: 150,
          height: 213,
          child: Column(
            children: [
              Image(image: flutterImageProvider),
              Text("Pixel color at top-left: $color."),
              Text("And brightness: $brightness."),
            ],
          ),
        );
      },
    );

Do you have any idea to solve my problem Thanks

marcglasberg commented 10 months ago

Hey, I'm glad you like the package!

It was not really created with SVG in mind, and I don't have the time at the moment to study the issue. I'll leave this issue open and mark it as "help wanted" in case someone can contribute a PR.

luuquangxinhzaiii commented 10 months ago

I see, thank you so much