'Flutter User ColorFiltered to dark image with matrix
I want in flutter to user ColorFiltered, so i can make jpg image dark here is my code but i didn't get the right result, i don't understand matrix and how to change color this code was from internet, please any idea will be welcome.
ColorFiltered(
child: ColorFiltered(
child: Image.asset(
'myimage.jpg',
fit: BoxFit.fill,
),
colorFilter: ColorFilter.matrix(
[
//R G B A Const
-1, 0, 0, 0, 190, //
0, -1, 0, 0, 255, //
0, 0, -1, 0, 255, //
0, 0, 0, 1, 0, //
],
),
),
colorFilter: ColorFilter.mode(
Colors.white,
BlendMode.darken,
),
)
Solution 1:[1]
If you just want to make your image darker the better solution is probably just putting a transparent black Container
over your image with a Stack
widget:
Stack(children: <Widget>[
Image.network('https://picsum.photos/250?image=9'),
Positioned.fill(
child: Opacity(
opacity: 0.5,
child: Container(
color: const Color(0xFF000000),
),
),
),
]),
If you really want to use ColorFiltered
let me know but you can do something like this:
ColorFiltered(
child: Image.network('https://picsum.photos/250?image=9'),
colorFilter: const ColorFilter.mode(
Color(0xFF3D3D3D),
BlendMode.darken,
),
),
Keep in mind that ColorFiltered
will not just add a new grey layer over the image. It transforms every pixel of the image separately.
As per the documentation:
This widget applies a function independently to each pixel of child's content, according to the ColorFilter specified.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |