Re: Adding a shadow to a UIImage in a UIImageview

2009-12-20 Thread Development
Ok so after a couple suggestions and rereading the Quartz information on 
shadows I modified my code but it's mostly all redundant since the shadow color 
is whatever the image color is and I cant seem to change that. Anyway Below is 
the code I am trying to use to draw a drop shadow under a UIImage inside of a 
UIImage view and it just isn't working. Sometimes I get a duplicate of the 
image with no color change, sometimes the image is clipped randomly and other 
times the image simply vanishes from the image view: P.S. I realize some of 
this code is useless but as you can see it was based on the apple example code.

UIGraphicsBeginImageContext(self.frame.size);
CGContextRef myContext =  UIGraphicsGetCurrentContext();
CGSize  myShadowOffset = CGSizeMake (5,  10);// 2
float   myColorValues[] = {0, 0, 0, .3};// 3
CGColorRef  myColor;// 4
CGColorSpaceRef myColorSpace;// 5
CGImageRef imgRef = rotatingView.image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);

CGContextSaveGState(myContext);// 6

CGContextSetShadow (myContext, myShadowOffset, 5); // 7
// Your drawing code here// 8
CGContextSetRGBFillColor (myContext, 0, 1, 0, 1);
   // CGContextDrawImage(myContext, CGRectMake(0, 0, width, height), imgRef);
[rotatingView.image drawInRect:self.frame];
myColorSpace = CGColorSpaceCreateDeviceRGB ();// 9
myColor = CGColorCreate (myColorSpace, myColorValues);// 10
CGContextSetShadowWithColor (myContext, myShadowOffset, 5, myColor);// 11
// Your drawing code here// 12
CGContextSetRGBFillColor (myContext, 0, 0, 1, 1);
//CGContextDrawImage(myContext, CGRectMake 
(width/3-75,height/2-100,width/4,height/4),imgRef);
[rotatingView.image drawInRect:CGRectMake 
(width/3-75,height/2-100,width/4,height/4)];
CGColorRelease (myColor);// 13
CGColorSpaceRelease (myColorSpace); // 14

UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
CGContextRestoreGState(myContext);
UIGraphicsEndImageContext();

rotatingView.image = 
imageCopy;___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Adding a shadow to a UIImage in a UIImageview

2009-12-19 Thread Development
I have subclassed UIImageView and am trying to add a shadow to the image inside 
of it. However I'm not getting anything at all and I'm not sure what to do.

Below is the code I am using for this:

-(void)addShadow
{
UIGraphicsBeginImageContext(self.frame.size);//If I don't add this line 
I get invalid context error.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShadow(context, CGSizeMake(.5,.5),.2);
[self setNeedsDisplay];
}___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com