Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add drop shadow to png image

I want to add a drop shadow to a png image (image with alpha) in flutter.

I've already tried using BoxShadow, but I don't want to have a box shadow. I need a shadow that adapts to the png image.

Desired result: Desired result

like image 724
Lukas Schneider Avatar asked Jul 20 '19 09:07

Lukas Schneider


People also ask

How to add drop shadow to a PNG image using CSS?

The CSS box-shadow property permits adding shadows on images. However, we can't utilize it with png images as it will put a square image shadow. If you need to make a drop shadow for the png image, the most choice decision is the filter property, that can help you with taking care of styling problems.

What is the difference between normal shadow effect and box-shadow effect?

The normal shadow effect will always put a square image shadow for the image which can be squared or cannot be squared but the shadow will be always square. filter:drop-shadow (); and text-shadow (); property is more eye pleasant compare to box-shadow: () property.

What are the parameters of drop shadow in JavaScript?

The value of the property is called drop-shadow (), and inside it are the following parameters: x-offset: The horizontal offset of the shadow. y-offset: The vertical offset of the shadow. blur-radius: The blur radius of the shadow. color: The color of the shadow.


2 Answers

First, you need two images, change the color of one them(your images should be transparent to make this happen) like:

child: Image.asset("assets/cat.png", color:Colors.black,),

Then put black one to the background using Stack and change its position to match shadow position.

Then add BackdropFilter to black one.

I think will work.

Code:

Stack(children: [
    Opacity(child: Image.asset(imagePath, color: Colors.black), opacity: 0.2),
    ClipRect(child: BackdropFilter(
        filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
        child: Image.asset(imagePath)))
])
like image 146
Payam Khaninejad Avatar answered Sep 23 '22 05:09

Payam Khaninejad


Try this package:

https://pub.dev/packages/simple_shadow

It's very configurable, and this is an example:

Container(
              child: SimpleShadow(
                child: Image(
                  width: 70.0,
                  height: 70.0,
                  image: NetworkImage(logoUrl),
                  semanticLabel: title,
                ),
                opacity: 0.25, // Default: 0.5
                color: Colors.black, // Default: Black
                offset: Offset(3, 3), // Default: Offset(2, 2)
                sigma: 7, // Default: 2
              ),
            ),
like image 31
Erich García Avatar answered Sep 21 '22 05:09

Erich García