Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is drawInContext so slow here?
    primarykey
    data
    text
    <p>I'm using the QuartzImage class in one of the demo projects and what I'm was trying to achieve was a simple frame display unit that basically draws an image (320x480) every 1/10th of sec. So my "frame rate" should be 10 frames per sec. </p> <p>In the QuartzImage demo class, there is a drawInContext method and in this method, it's basically drawing a CGImageRef using the CGContextDrawImage(), I measured the time it took to finish complete and it's taking on average around ~200ms.</p> <pre><code>2011-03-24 11:12:33.350 QuartzDemo[3159:207] drawInContext took 0.19105 secs -(void)drawInContext:(CGContextRef)context { CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); CGRect imageRect; imageRect.origin = CGPointMake(0.0, 0.0); imageRect.size = CGSizeMake(320.0f, 480.0f); CGContextDrawImage(context, imageRect, image); CFAbsoluteTime end = CFAbsoluteTimeGetCurrent(); NSLog(@"drawInContext took %2.5f secs", end - start); } </code></pre> <p>Can anyone explain why it's taking that long and if there is any other way of improving the performance? 200ms just seems much more longer than it should have taken.</p> <p><strong>UPDATES</strong> I tried @Brad-Larson's suggestion but not seeing a lot of performance improvement. </p> <p>So the updated version is I got my own class </p> <pre><code>@interface FDisplay : UIView { CALayer *imgFrame; NSInteger frameNum; } end </code></pre> <p>So in my Class implementation </p> <pre><code>- (id)initWithFrame:(CGRect)frame { ............ frameNum = 0; NSString *file = [NSString stringWithFormat:@"frame%d",frameNum]; UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:file ofType:@"jpg"]]; imgFrame = [CALayer layer]; CGFloat nativeWidth = CGImageGetWidth(img.CGImage); CGFloat nativeHeight = CGImageGetHeight(img.CGImage); CGRect startFrame = CGRectMake(0.0, 0.0, nativeWidth, nativeHeight); imgFrame.contents = (id)img.CGImage; imgFrame.frame = startFrame; CALayer *l = [self layer]; [l addSublayer:imgFrame]; } </code></pre> <p>I have a NSTimer going at 0.1f calling my refresh method</p> <pre><code>NSString *file = [NSString stringWithFormat:@"frame%d",frameNum]; UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:file ofType:@"jpg"]]; frameNum++; if (frameNum&gt;100) frameNum = 0; [CATransaction begin]; [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; [imgFrame setContents:(id)img.CGImage]; [CATransaction commit]; end = CFAbsoluteTimeGetCurrent(); NSLog(@"(%d)refresh took %2.5f secs", [[self subviews] count],end - start); </code></pre> <p>I think I got everything right but the frame rate is still way low, </p> <pre><code>refresh took 0.15960 secs </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload