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".
Related
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.
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.
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
I have a UIImage, the background of it is white. I want the background of this UIImage to be transparent to its parent view. Is this possible?
One word answer- No. As robin said you have to use photo editing softwares to accomplish that. it cannot be done iphone(easily)..
I am not going to suggest that it is easy, but you should take a look at CGImageCreateWithMaskingColors, which is described in the Quartz 2D Programming Guide: Bitmap Images and Image Masks
You can't specify the transparency of a color from an image, but you could make a PNG image which has a transparency in the places you want it to be transparent.
I have several rectangular images (in landscape and portrait mode) and want to draw them onto a transparent square image, so that all images became the same size without cropping them. How would I create a transparent UIImage and draw another on top?
Thanks for any hints.
Create a bitmap graphic context with CGBitmapContextCreate. You'll need to determine what the size of the resulting composite image here. You can think of this as a sort of canvas.
Draw the images using CGContextDrawImage. This will draw images onto the same context.
Once you're done drawing all the images into the same context, create an image from that context with CGBitmapContextCreateImage.
Convert the Core Graphics image from step #3 into a UIImage with [UIImage imageWithCGIImage:].
Code examples can be found here.