0

I have 4 UIViews each view contains around 16 UIImageViews. And i am applying mask to all the UIImageViews through below code

-(void)setMask:(UIImage*)maskImage forImageView:(UIImageView*)imageView
{
    CALayer *mask = [[[CALayer alloc] init] autorelease];
    mask.contents = (id)[maskImage CGImage];
    mask.frame = CGRectMake(0, 0, 1024, 768);
    imageView.layer.mask = mask;
    imageView.layer.masksToBounds = YES;
    return;
}

Is this right code for UIImageView masking ?

Each UIImageView is changes image through mask. But after changing images in more than 5 UIImageView "Receive memory warning." appears and it crashes. All the images are in 1024*768 resolutions , even mask images too.

Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
DipakSonara
  • 2,598
  • 3
  • 29
  • 34
  • I don't know if your maskimage is the problem or the actual images in your uiimageviews. Check this post and see if it helps. http://stackoverflow.com/questions/12773074/received-memory-warning-on-setimage – Sam B Jun 13 '13 at 13:31

2 Answers2

1

Try with this "

UIGraphicsBeginImageContextWithOptions

But I'm not sure this will help you or not . but I have been using it for many of situations , I didn't get any of warning from it . Try It may be helpful . Something like this :

UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0); //retina res
[self.imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
[imageView.image drawInRect:CGRectMake(0, 0, 703, 294)];
[maskImages.image drawAtPoint:CGPointMake(10, 10) blendMode:kCGBlendModeNormal alpha:0.2];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
-1

You have ever use creating mask using CGContextClipToMask i think it will work and will not give you memory warnings. You are using so many imageview. hows it's performance in retina? is it work in that with all that masking.

Amrit Trivedi
  • 1,240
  • 1
  • 9
  • 24