Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you are doing right now is creating a paired <code>CGImage</code> and <code>CGBitmapContext</code> for every call to <code>drawSquareFrom:to:</code> and disposing them each time. Instead, create a single paired <code>CGImage</code> and <code>CGBitmapContext</code> that you reuse for each call.</p> <pre><code>-(void) drawSquareFrom:(CGPoint)from to:(CGPoint)to { CGContextRef context = [self offscreenContext]; CGRect draw , full = [self offscreenContextBounds]; draw.origin = from; draw.size.width = to.x - from.x; draw.size.height = to.y - from.y; draw = CGRectStandardize( draw ); [[UIColor redColor] setStroke]; [[UIColor clearColor] setFill]; CGContextClearRect( context , full ); CGContextFillRect( context , draw ); CGContextStrokeRectWithWidth( context , draw , 10 ); [_imageView setNeedsDisplay]; } </code></pre> <p>You create a paired CGImage and CGContext like this, although there are some ... to fill in. All the myX variables are intended to be class members.</p> <pre><code>-(CGContextRef) offscreenContext { if ( nil == myContext ) { size_t width = 400; size_t height = 300; CFMutableDataRef data = CFDataCreateMutable( NULL , width * height * 4 ); // 4 is bytes per pixel CGDataProviderRef provider = CGDataProviderCreateWithCFData( data ); CGImageRef image = CGImageCreate( width , height , ... , provider , ... ); CGBitmapContextRef context = CGBitmapContextCreate( CFDataGetMutableBytePtr( data ) , width , height , ... ); CFRelease( data ); // retained by provider I think CGDataProviderRelease( provider ); // retained by image myImage = image; myContext = context; myContextFrame.origin = CGPointZero; myContextFrame.size.width = width; myContextFrame.size.height = height; _imageView.image = [UIImage imageWithCGImage:image]; } return myContext; } -(CGRect) offscreenContextBounds { return myContextFrame; } </code></pre> <p>This sets the _imageView.image to the newly created image. In <code>drawSquareFrom:to:</code> I assume that setNeedsDisplay is sufficient to draw the changes to made, but it may be that you need to assign a new UIImage each time that wraps the same CGImage.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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