Douglas
Douglas

Reputation: 37763

Duplicate UIViews

I'd like to display the same UIView multiple times. At the moment, I have my drawing in a primary UIView, then copy this into an image using renderInContext: and UIGraphicsGetImageFromCurrentImageContext. Then I set the contents of the other proxy UIViews to be this image.

 UIGraphicsBeginImageContext(size);

 [self.layer renderInContext:UIGraphicsGetCurrentContext()];

 UIImage * clonedImage = UIGraphicsGetImageFromCurrentImageContext();

 UIGraphicsEndImageContext();

 return [clonedImage CGImage];

I'm experiencing a bottleneck in the renderInContext: call, presumably because it has to copy the image of the view. I'm seeing hot spots in resample_byte_h_3cpp and resample_byte_v_Ncpp, but I'm not sure what these are doing.

Is it possible to display the same UIView multiple times to reduce this overhead? Or is there a more efficient way to render the image?

Upvotes: 0

Views: 969

Answers (1)

runmad
runmad

Reputation: 14886

How about making a copy of the UIImage instead of generating new images over and over from the UIView?

//.. Create the clonedImage from UIView

CGImageRef cgImageRef = [clonedImage CGImage];
UIImage *twinImage = [[UIImage alloc] initWithCGImage:cgImageRef];

//.. Use the images

[clonedImage release]; // if needed
[twinImage release]; // if needed

Upvotes: 1

Related Questions