FROM : Bridger Maxwell
DATE : Mon Jan 07 19:39:37 2008
Hello,
RIght now I am making a Core Animation program that displays photos. This
is the code I use to draw the image (inside the CALayer), along with a
slightly transparent black background and a white border.
- (void) setImage: (CGImageRef)image bounds: (CGRect)rect
{
self.contents = (id) image;
self.contentsGravity = @"resize";
self.minificationFilter = kCAFilterLinear;
self.bounds = rect;
CGFloat border = MAX(CGRectGetHeight(rect),CGRectGetWidth(rect));
border /= 60;
self.borderWidth = border;
self.borderColor = CGColorGetConstantColor(kCGColorWhite);
CGColorRef background = CGColorGetConstantColor(kCGColorBlack);
background = CGColorCreateCopyWithAlpha(background,0.8);
self.backgroundColor = background;
}
The only problem is that the border is drawn over the image, because it is
drawn inset from the bounds, and the contents of the layer go right to the
edge. Is there a way to either have the image draw itself a little ways out
from the bounds (to leave room for a border) or to draw the border outset
from the bounds? I suppose I could make another layer within this one to
hold the image, but being a new Cocoa programmer I am a little worried about
making my program any more complicated than it needs to be.
Thank You,
Bridger Maxwell
DATE : Mon Jan 07 19:39:37 2008
Hello,
RIght now I am making a Core Animation program that displays photos. This
is the code I use to draw the image (inside the CALayer), along with a
slightly transparent black background and a white border.
- (void) setImage: (CGImageRef)image bounds: (CGRect)rect
{
self.contents = (id) image;
self.contentsGravity = @"resize";
self.minificationFilter = kCAFilterLinear;
self.bounds = rect;
CGFloat border = MAX(CGRectGetHeight(rect),CGRectGetWidth(rect));
border /= 60;
self.borderWidth = border;
self.borderColor = CGColorGetConstantColor(kCGColorWhite);
CGColorRef background = CGColorGetConstantColor(kCGColorBlack);
background = CGColorCreateCopyWithAlpha(background,0.8);
self.backgroundColor = background;
}
The only problem is that the border is drawn over the image, because it is
drawn inset from the bounds, and the contents of the layer go right to the
edge. Is there a way to either have the image draw itself a little ways out
from the bounds (to leave room for a border) or to draw the border outset
from the bounds? I suppose I could make another layer within this one to
hold the image, but being a new Cocoa programmer I am a little worried about
making my program any more complicated than it needs to be.
Thank You,
Bridger Maxwell
| Related mails | Author | Date |
|---|---|---|
| Bridger Maxwell | Jan 7, 19:39 | |
| Scott Anguish | Jan 7, 19:43 | |
| Bridger Maxwell | Jan 7, 21:17 | |
| David Duncan | Jan 7, 23:03 | |
| Scott Anguish | Jan 8, 21:09 | |
| Scott Anguish | Jan 8, 21:10 |






Cocoa mail archive

