I want to implement alpha gradient on an image. From 0.5 alfa on top of the image to 0.0 on bottom.
Any advice, tutorial, link is welcome.
I want to implement alpha gradient on an image. From 0.5 alfa on top
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
CGImageCreateWithMaskto apply a masking image to it. You could generate an appropriate mask simply enough by drawing to a greyscale or alpha-only CGBitmapContext withCGContextDrawLinearGradient.If it’s being displayed as the content of a CALayer, you could apply an appropriate masking layer to the parent layer’s
maskproperty. You could use aCAGradientLayerwith appropriate colors to create this mask.You can draw the image to a CGBitmapContext, and then draw an appropriate alpha gradient over it using
kCGBlendModeDestinationIn. Or draw the gradient first, and draw the image over it usingkCGBlendModeSourceIn. In both cases,CGContextDrawLinearGradientis again your friend. Then, of course, get the image out of the CGContext usingCGBitmapContextCreateImageorCGImageCreateon the underlying data buffer.Or, of course, if you control the original image and never need a version without the alpha gradient, you could just store it as a PNG with the appropriate alpha values in the first place.