What is the best approach to display a cropped/masked image in Flutter?
Lets say I have one image with a mask (eg. an irregular star shape with transparent background) and the other image which I want to mask with this star, so that only the part inside the star of original image would be rendered.
I'm aiming for something like PorterDuffXfermode on Android (similar question here - Android how to apply mask on ImageView?).
In case of simple mask shapes is going the RenderClipOval way a good approach?
I would just paint it using a CustomPainter, setting the Paint.BlendMode on the Paint you pass to the method when you paint the image.
See https://docs.flutter.io/flutter/dart-ui/Canvas/drawImageRect.html and https://docs.flutter.io/flutter/dart-ui/Paint/blendMode.html and https://docs.flutter.io/flutter/widgets/CustomPaint-class.html.
Related
I have an image in the image view. When user taps on the image, it makes a part of the image blur. This part is working fine (as expected). But, if the part if already blurred then I do not want it to be blurred further. Can you give me a clue on how it can be achieved ? Consider any general image.
Either keep the original image and the blurred image separately as Alexander suggests, or keep a mask that lets you track what parts of the image have already been blurred, and mask away the already-blurred areas before applying your blur filter again.
Does the image have to blur by being touched or can it just look like it is? What if you loaded the original image on top of a blurred version of the image and erased the top layer on touch? Kind of renders your blurring function useless though.
It's a pretty hacky way to do it, but unless you want to keep track of a list of every pixel that was altered like Alexander said, I can't think of another way. That way you can just apply the blur to the already unaffected ones.
I would like to create the same effect that you can see on the picture attached.
I would like to have that kind of effect over my barcode scanner, which scan barcode with phone camera.
Any idea how can I do this?
I already tried with shadows but that was not the effect I want.
Thank you.
It looks like the
CILenticularHaloGenerator core image filter simulates lens flare, although the appearance is different than what you show.
Your image looks more like a radial gradient in red drawn over your image. You could use the Core Image CIRadialGradient filter, or overlay a partly transparent gradient on top of your image using CGGradient and CGContextDrawRadialGradient.
I am trying to make Apple kind of shape for progressHUD. I have option to use .png Image but I cant because I have to fill the apple Shape with different colour depends of percentage status.. I am using UIView to draw this shape...
I want suggestion how to draw apple kind of shape easily?
And How we can fill half colour with different colour?
I have option to use .png Image but I cant
Yes, you can. — Get hold of some apple-shaped artwork. Use it as a mask - it punches a hole in a view. Now put another view behind it, with a color. Now the apple appears to be that color, because that color is being seen through the apple-shaped hole. Now put another view behind it, with a different color, and move it up or across the right amount so as to divide what's seen through the apple into two colors.
Using that approach, it took me about 30 seconds to create this result (using your apple-shaped artwork as a .png image!):
Hello: Currently in my project, I'm using OBShapedButton to process touches on a lot of objects that overlap (it's a map with each territory its own separate object). Basically, this library prevents a touch from being processed on a transparent point on the given view.
I'm attempting to add a border effect to just the edges of the opaque part of the UIImage (and adding a semi-transparent overlay above that). Something to the effect of this:
Which can be simplified to this (example of one image):
I am currently using MGImageUtilities to color in the opaque parts of territories using this line:
[territory setImage:[[territory image] imageTintedWithColor:tint]];
The problem is that I'm not sure how to just color the borders (which can be any shape). I've looked at this link already, but haven't been able to come up with anything.
Thanks in advance for the help!
Terribly hacky, but use MGImageUtilities' UIImage+ProportionalFill with scale resizing to create a slightly larger image, UIImage+Tint to red, and stack below.
The library you are using doesn't actually specify a shape layer. It uses alpha values from the PNGs that you give it.
Could you use a different 'highlighted' or 'selected' PNG that adds the border effect you are looking for?
Otherwise, it you will have to generate a UIBezierPath from your PNG image, which sounds like a very computationally intensive operation. At that point, I might question whether this library meets your needs.
How can I change hue of an UIImage programmatically only in few parts? I have followed this link
How to programmatically change the hue of UIImage?
and used the same code in my application. It's working fine but the complete image hue is getting changed. According to my requirement I want to change only the tree color in the above snap. How can I do that?
This is a specific case of a more general problem of using masking. I assume you have some way of knowing what pixels are in the "tree" part, and which ones are not. (If not, that's a whole other question/problem).
If so, first draw the original to the result context, then create a mask (see here: http://mobiledevelopertips.com/cocoa/how-to-mask-an-image.html), and draw the changed-hue version with the mask representing the tree active.
I recommend you take a look at the CoreImage API and the CIColorCube or CIColorMap filter in particular. Now how to define the color cube or color map is where the real magic lies. You'll need to transform tree tones (browns, etc), though this will obviously transform all browns, not just your tree.