Apply a mask to an iPhone application - iphone

i found a tutorial that explain how apply a mask on an UIImage, but i have a problem.
this is the link:
http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
If i apply a mask to an image taken by a picker with "picker.alowsEditing=YES" the mask is applyed well and the background of the image is the same color of the application's backgroung, and is good.
But if the option is "picker.alowsEditing=NO" when i apply the mask the image's background become black.

Hi i undstend that the problem is the alpha layer.
If an image have not an alpha layer can't use the mask, otherwise the image background will be colored Black.
To add an alpha layer (layer with alpha channel) to an image i found an userfull guide here:
http://pastie.org/418627

Related

Blur part of an image

I want to blur part of a image. I could blur the full image blurred using CIFilter ("CIGaussianBlur") but not a part of it.
For example: I want to blur the image in a small circular or square shape wherever the user taps the image.
How can I do that?
You know how to blur a whole image so you can draw the touched part of the image into a new image, blur that, and then draw it over the original at the touched point.
There are several approaches. One would be to create a CIImage greyscale mask image with the shape you want, a blurred CIImage (using CIGaussianBlur), and then use CIBlendWithMask to blend them together.
The inputs of CIBlendWithMask are the input image (the blurred image), the input background image (the unblurred image), and the mask image (the shape you want). The output is the image you desire.

How to mask image with color in iOS?

Basically I want to remove the background color of image from image.
that why I want to mask my image with clear color, it can make the image transparent.
or do we have any other way to clear the backgrund color of image and get transparent image.
Create a new image with by masking background using CGImageCreateWithMaskingColors. Specify the background color range(RGB) values. That would be enough to create background transparent image.

Edge blending of image with alpha on iOS after masking color

I have an image that has been masked with a range of colors using
CGImageCreateWithMaskingColors()
Everything works fine, but the edge of the image (we are using a green screen for profile pictures) is pixelated. I've tried drawing the image in an image context and a bitmap context with the proper antialiasing, but the edges remain the same.
Any suggestions on how to smooth the sides of the profile after it has been masked?
You could try zooming the mask image larger by some multiple (say 2X, 3X or 4X) before creating the mask. Then a size-reduced copy of this larger mask might be better antialiased.

Alpha blending on the edges of an UIImage

I have two rectangular images: one is foreground, the other one is background. I am trying to blend the edges of the foreground image so that the foreground image looks like it is "part" of the background image. In other words, I am trying to apply a transparency effect, with the opacity of the foreground image decreasing from 100% at the center of the image down to 0% at the edges. I have found that this operation is sometimes referred by different names, such as: alpha compositing, alpha blending, edge feathering or edge transparency. Here is a more detailed description of the effect I am trying to obtain: http://en.wikipedia.org/wiki/Alpha_compositing
I have looked at the CGContext documentation, but I haven't found any function that would do that out of the box.
Is there any way to do that using CGContext or even OpenGL? Would there be a way to do it on a non-rectangular image? I know, all images are rectangular, but I mean an image with let's say, a circle in it, and a transparent area all around.
The CGImageCreateWithMask() function in the iOS library can do alpha blending with decreasing opacity on the edges. It's possible to get something to work by combining the code in these two links:
http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
Creating mask with CGImageMaskCreate is all black (iphone)
The level of gray (from black to white) of each pixel in the mask will define the level of opacity during blending.

How to shade a png image for iphone

I have a UIImage that is displaying a grayscale button. Is there a way to "shade" the image with a color when i draw it? So i could effectively have 1 grayscale button image, but have any color button? I would also like to have the transparent pixels stay transparent if possible.
Thanks!
To do this, you'll need to use Quartz 2D with the following steps:
Create a CGImage for the PNG background with CGImageCreateWithPNGDataProvider, or use UIImage as usual and grab a reference to the Quartz image data using the CGImage property of the UIImage.
Set the blend mode on the image with CGContextSetBlendMode. The mode you're after is probably kCGBlendModeOverlay.
Create a new single-tone CGImage for the shading layer.
Use CGContextDrawImage to composite the shading layer over the background layer.
Detailed instructions on how to do this are available in the Quartz 2D Programming Guide, in the section titled "Using Blend Modes with Images".