IOS Extract Output Image from Masked Image - ios

I have created an image mask based on user input, and the result includes both foreground and the created mask (mixed).
Masked Image
I am trying to find a way to return only the masked image, and have been unsuccessful identifying a way to change the alpha value of the mask. Can anyone help? I want to get to a final image of the selected area.
The code I am working with to create the mask and return the masked image is here: Code Sample

After continuous research and testing, I used the getForeground:andMask method to separate the target into two sets of values. Then, I inverted the mask and added the resulting image and inverted mask to a SubView with a clear background color.

Related

Mask/crop an image

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.

Create new image using just some pixels data from the source image based on them color

I have original image and I can cycle all pixels using #patrick-rutkowski answer here. Also I have this answer seems to create image with pixel data. But I can't understand how to combine these two answers. So the first task is get pixel and second is add it to another CGImage. For example if I want to extract all red pixels from the original image and add these red pixels to another image. I suppose it's way to go.

Apply a CIFilter to a UIView & all subviews

I have a UIView, that contains a UIImageView for its background. The view contains a number of segments (UIImageViews), which the user can drag and drop images to. I want to add a CIFilter to the whole view, such that any images that are subsequently dropped into the view will have the filter applied instantly. But the filter shouldn't be applied to the main view's background image. I realise that a CIFilter requires an input image, I was thinking of using a transparent input image, then placing the filter on top of all the views so it would only be visible when there is an image behind it.
Is it possible to supply a transparent input image to a CIFilter?
Is this the best way of going about it?
I suppose I'd need to mask the filter to the view containing the segments so that it is not applied to the background image. How would I go about this? Since a mask needs an image to mask to, I guess I'd need to render the segments view to an image and mask to this?
Thanks in advance

Create iOS mask image on the fly

I got an image I want to mask on the fly. The mask is basically shaped like a part-circle and changes in volume from time to time. Therefor I need to create an in-memory image, draw the mask circle stuff to it and do the masking on the original image like described in How to Mask an UIImageView.
The thing is that I got no idea how to create an in-memory image I may use for masking and I can apply basic drawing opperations on.t
If your mask is only a semi-circle, it might be easier to create a clipping path with CGContext* calls and draw your image as a CGImage with the clipping path applied. See the documentation for CGContextClip() for details.

How can I change hue of an UIImage programmatically only in few parts?

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.

Resources