iphone - Create new UIImage by adding shadow to existing UIImage -


I have taken a look at this question:

but did not work for accepted answers.

What am I trying to do is taking a UIImage and putting shadows in it, then a new new UI, shadow and all come back.

Trying:

- (UIImage *) Image Shadow {CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB (); CGContextRef shadowContext = CGBitmapContextCreate (NULL, self.size.width, self.size.height + 1, CGImageGetBitsPerComponent (auto.cnmage), 0, color touch, kCGImageAlphaPremultipliedLast); CGColorSpaceRelease (colourspace); CGContextSetShadow (Shadow Contact, CGSizeMake (0, -1), 1); CGContextDrawImage (Shadow Context, CGRactMake (0, 0, Self Skies.Wedth, Spie. Size.height), Self. CGImage); CGImageRef shadowedCGImage = CGBitmapContextCreateImage (ShadowContext); CGContextRelease (shadowContext); UIImage * Shaded Image = [UIImage imageWithCGImage: shadowedCGImage]; CGImageRelease (shadowedCGImage); Return shadowed image; }

The result is that before I keep it through this method, I get the same image in the same way.

Am I doing this correctly, or is it something I'm clearly missing?

There are several problems with your code:

  • Target image too small Make sure there is enough space to attract the shadow.
  • Consider using CGContextSetShadowWithColor to define both the shadow and its color.
  • is flipped, so the original is bottom-left, not top-left.

By fixing these issues, the shadra should be drawn.

  - (UIImage *) Imagewindows {CGColorSpaceRef color space = CGColorSpaceCreateDeviceRGB (); CGContextRef shadowContext = CGBitmapContextCreate (NULL, self.size.width + 10, self.size.height + 10, CGImageGetBitsPerComponent (auto.cnmage), 0, colorspace, kCGImageAlphaPremultipliedLast); CGColorSpaceRelease (colourspace); CGContextSetShadowWithColor (Shadow Contact, CGSizeMake (5, -5), 5, [UIColor blackColor] .CGColor); CGContextDrawImage (Shadow Context, CGRactMake (0, 10, Self Skies.With, Self Size.,), Self. CGImage); CGImageRef shadowedCGImage = CGBitmapContextCreateImage (ShadowContext); CGContextRelease (shadowContext); UIImage * Shaded Image = [UIImage imageWithCGImage: shadowedCGImage]; CGImageRelease (shadowedCGImage); Return shadowed image; }  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -