I want to put a color filter over an asset image.
As below, I currently have an image with colorBlendMode filter, but I want to be able to directly fix the RGB value of each pixel of the image.
Does anyone know how this can be done?
body: Center(
child: new Image.asset(
'assets/gallery/garrowby_hill.jpg',
width: size.width,
height: size.height,
fit: BoxFit.fill,
color: Color.fromRGBO(redCount, greenCount, blueCount, 1),
colorBlendMode: BlendMode.multiply,
),
),
You can use a ColorFiltered class and use your image as it's child and use colorFilter property ,
TODO:
Wrap your Image.asset in a new Widget called ColorFiltered
add a new property for this widget : colorFilter: ColorFilter.mode(your_color_here, BlendeMode.your_blendMode_here).
You can check those links : ColorFilter Class, colorFilter propery and it's used in this video
Related
I'm dealing with the template png which has a boxed place where I need to fit any size image within that box. How can fit all dimension image to fit in that box in flutter?. I have attached the image.
I need to add image in that black area which is PNG image and what I tried to implement is here.
body: Stack(
children: [
Positioned(
top: MediaQuery.of(context).size.height / 3.5,
right: MediaQuery.of(context).size.width / 10,
child: imagePicked == null
? SizedBox()
: AspectRatio(
aspectRatio: 1,
child: Image.file(imagePicked, fit: BoxFit.fill),
),
),
const Positioned.fill(
child: Align(
alignment: Alignment.centerRight,
child: Image(image: AssetImage('assets/images/notice.png')))),
],
),
But Here I couldn't manage all dimension images. Please help me sort to fit any dimension image into that black box which is also a template image.
The main issue is here overlaying with stack's widgets.
Widget render prioritize bottom to top level on Stack.
In your code-snippet, place-holder is the bottom widget, and it is being prioritized over the selected image.
That's why putting place-holder as 1st widget on stack solve the issue.
Currently I am using ColorFilter for giving opacity to decoration image of container.
For Image.asset or Image.network we can use like:
Image.network(
'url',
color: Color.fromRGBO(255, 255, 255, 0.5),
colorBlendMode: BlendMode.modulate
),
So is their any such alternative for decorationImage??
Thanks in advance for answer and your valuable time.
ColorFiltered(
colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.dstATop),
child: YourWidget(),
)
I want to create a stack of images with a carousel effect, details of the image will be displayed below in a different container. While swiping an image from the stack, details will be changed with the image.
Already done with the image carousel part and swiping.
CarouselSlider(
viewportFraction: 0.7,
aspectRatio: 1,
autoPlay: true,
enlargeCenterPage: true,
items: carouselList.map(
(image) {
return Container(
margin: EdgeInsets.all(5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
image:
DecorationImage(image: AssetImage(image), fit: BoxFit.cover),
),
);
},
).toList(),
);
How to change the details of the image while swiping an image from the stack?
Want to achieve a slider like the below image.
Have you checked out this in the package where you can create your own dynamic tree:
CarouselSlider.builder(
itemCount: 15,
itemBuilder: (BuildContext context, int itemIndex) =>
Container(
child: Text(itemIndex.toString()),
),
)
your carouselList will be list of class object where you have the title,release_date , ratings and the image. passing the list to the builder will render the every object up to that length.
Maybe I am late but check this package
I am trying to show a CircleAvatar at the top of the main screen of my App, but I am running into a rather silly issue. I am unable to figure out how to provide an object of the class Image (that is a property of a user) as an ImageProvider, which is what CircleAvatar expects. Is there an easy way to "typecast" here or some other way people have resolved this?
class _HomePageState extends State<PictureShowcaseHome>{
Appuser appuser = new Appuser();
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: InkWell(
child: CircleAvatar(
backgroundImage: appuser.img,
child: Text(appuser.name.substring(0,1).toUpperCase()),
) ,
),
...
To simplify things, assume an Appuser has just the following properties:
class Appuser{
String name;
Image img;
Appuser(){
this.name = "Unknown user";
this.img = Image.asset('assets/imgs/default1.jpg');
}
}
My idea is that I have a default image that is included in the assets, but the user can replace it with their own image (seems like a rather standard idea). I considered switching to AssetImage img; and img = new AssetImage('assets/imgs/default1.jpg'); in the constructor for Appuser, but that sort of seems backwards. It also gets me into the "opposite" problem, when I display the user image on a user information details page (I thought of just having a ListTile( title: appuser.img,),) or when I let the user take a new user picture with the camera. For those purposes, it is easiest to directly work with an object of class Image, not an AssetImage.
Or am I somehow looking at this the wrong way?
This
Image.asset('assets/imgs/default1.jpg').image
should work.
For the sake of clarity, the Image class has an ImageProvider property. Just get the ImageProvider using .image with any given Image class. This works for Image.asset, .file, .network, and .memory
.image will give you the ImageProvider that is needed.
CircleAvatar(
backgroundColor: Colors.red,
radius: radius,
child: CircleAvatar(
radius: radius - 5,
backgroundImage: Image.file(
profileImage,
fit: BoxFit.cover,
).image,
),
)
How can I make the selected part in the image below as my background image?
You can use alignment property of Image or DecorationImage combined with fit.
Image.network(
'url',
alignment: Alignment.center,
fit: BoxFit.cover,
);