How to Darken an Irregularly Shaped Transparent CALayer on the iPhone?
NickName:Shannon A. Ask DateTime:2010-09-21T04:18:11

How to Darken an Irregularly Shaped Transparent CALayer on the iPhone?

I'm putting an image into a CALayer that could be irregularly transparent:

 theCardLayer.front = [CALayer layer];
 theCardLayer.front.contents = (id)[cardDrawing CGImage];

In other words, it might be a square filling the layer or it might be an octagon that leaves the corners see-through.

I want to sometimes darken this layer, but without darkening the see-through bits. Any suggestions for how to do so in a programmatic way?

Copyright Notice:Content Author:「Shannon A.」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/3755154/how-to-darken-an-irregularly-shaped-transparent-calayer-on-the-iphone

Answers
Ben Stiglitz 2011-04-01T21:40:10

Take a look at CGBlendMode; a multiply blend, done by creating a new CGBitmapContext, drawing the image and then a grey fill, and assigning the resulting image to your layer, should work nicely.",


More about “How to Darken an Irregularly Shaped Transparent CALayer on the iPhone?” related questions

How to Darken an Irregularly Shaped Transparent CALayer on the iPhone?

I'm putting an image into a CALayer that could be irregularly transparent: theCardLayer.front = [CALayer layer]; theCardLayer.front.contents = (id)[cardDrawing CGImage]; In other words, it migh...

Show Detail

Irregularly shaped forms

Many modern applications have irregularly shaped forms. What is the best way to do this in Delphi? Is it possible to do this without using any third party VCLs?

Show Detail

How to create a clickable irregularly-shaped region in c#

I have an irregularly-shaped picture like a heart or any random shape. I can make it transparent visually, but I need to make it clickable only on the shape area. I heard that I should use "Region"...

Show Detail

Randomly place an MovieClip on an irregularly shaped object?

Is there anyway to randomly place a MovieClip/Sprite on an irregularly shaped object? For a rectangle, it seems pretty straightforward (i.e. use Math.random with the range being the coordinates of...

Show Detail

Memory Leaks in Irregularly Shaped UIButtons

I know this is a long-shot, but since I need this code to work, maybe someone here can help. I'm using the Irregularly Shaped Buttons code from CodeProject.com in one of my iPhone apps. Works gre...

Show Detail

Fastest way (performance wise) to darken UIView or CALayer

I have a UIView / CALayer which I would like to darken. How can I as fast as possible darken it? Is there any way to avoid blending? Following alternatives is known to me create a non-opaque CALa...

Show Detail

Representing a Gameworld that is Irregularly shaped

I am working on a project where the game world is irregularly shaped (Think of the shape of a lake). this shape has a grid with coordinates placed over it. The game world is only on the inside of the

Show Detail

PyQt Irregularly Shaped Windows (e.g. A circular without a border/decorations)

How do I create an irregularly shaped window in PyQt? I found this C++ solution, however I am unsure of how to do that in Python.

Show Detail

Irregularly shaped Modal View on iPad

Is it possible to display an irregularly shaped Modal view using presentModalViewController? The modal is covering the screen partially (presentation style is set to UIModalPresentationFormSheet) I

Show Detail

Implementing irregularly shaped regions in a strategy game

I'm developing a strategy game for Android using libGDX. It's loosely based on Risk and requires irregularly shaped regions. However, I am having trouble deciding how to detect when a player touche...

Show Detail