I have been using the following code to create an image off the screen (creating a
context
, off-screen in background thread using GDC
) and later render it in the
main thread on the screen only when i receive updated "array of UIImages"
.
I found by doing so the rending path , lines .etc was much faster then dowing it the
drawRect: method of the UIView .
The issue that I'm facing now is that when trying to rending UIImage class using
CGContextDrawImage()
it get really slow over ~1.4-2.5 sec to render. From searching
the main issue was that it spends most of its time deflating the png file. I have
tried infating the png image and use CGImageRef
still long rending time. I dont have
a control on the data array that contain list if png files it comes in.
Would breaking the image to small pieces or and, using CALayer
help , how i can stitch
those images without using "CGContextDrawImage
" is it possible ?
I'm not sure what is best way to fix this issues and how , any Idea ?
Thanks In Advance
void creatImageInBackground
{
size = CGSizeMake (self.frame.size.width,self.frame.size.height);
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
UIGraphicsPushContext(context);
for(UIImage * img in imgList )
{
ulXY = <calcuate >;
lrXY = <calcuate >;
imRec = CGRectMake( ulXY.x,-ulXY.y,(lrXY.x-ulXY.x) ,(lrXY.y -ulXY.y) );
CGContextTranslateCTM( context, 0,(lrXY.y-ulXY.y) );
CGContextScaleCTM(context, 1, -1);
CGContextDrawImage(context, imRec,[[img image] CGImage]);
//[img drawInRect:imRec];
}
UIGraphicsPopContext();
[outputImage release];
outputImage = UIGraphicsGetImageFromCurrentImageContext() ;
[outputImage retain];
UIGraphicsEndImageContext();
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self setNeedsDisplay];
[self setHidden:NO];
});
}
Then
- (void)drawRect:(CGRect)rect
{
CGPoint imagePoint = CGPointMake(0, 0);
[outputImage drawAtPoint:imagePoint];
}