image is blinking using the method drawInRect what am i doing wrong
<p>My code is here.</p>

<pre><code>-(void)displayPacketData:(NSData*)decompressedData:(CEZCmdZLIBCompress*)data
{
        Byte* d=[decompressedData bytes];
    int width=data-&gt;iWidth;
    int height=data-&gt;iHeight;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    size_t bitsPerComponent = 8;
    size_t bytesPerPixel    = 4;
    size_t bytesPerRow      = (width * bitsPerComponent * bytesPerPixel + 7) / 8;
    size_t dataSize         = bytesPerRow * height;
    context = CGBitmapContextCreate([decompressedData bytes], width, height, 
                                    bitsPerComponent, 
                                    bytesPerRow, colorSpace, 
                                    kCGImageAlphaNoneSkipFirst  | kCGBitmapByteOrder32Little);
    layer1 = CGLayerCreateWithContext(context,(struct CGSize){ width, height }, NULL);

    if( layer1 == NULL )
    {
        NSLog(@"Layer could not be created");
    }
    layerContext = CGLayerGetContext(layer1);
    CGContextScaleCTM(context, 1, -1);
    CGContextTranslateCTM(context, 0, height);

    //CGColorSpaceRelease(colorSpace);
    CGImageRef imageRef = CGBitmapContextCreateImage(context);
    UIImage *result = [[UIImage imageWithCGImage:imageRef] retain];
    m_image=result;
    x = data-&gt;iX;
    y = data-&gt;iY;
    h = height;
    w = width;
    //CGImageRelease(imageRef);
    //CGContextRelease(context);
    //free(data);    
    //[result drawInRect:CGRectMake(10.0, 30.0, x, y)];
    //CGContextRef currentContext = UIGraphicsGetCurrentContext();
    //CGContextDrawLayerAtPoint(context,CGPointZero,layer1);
    //CGContextDrawImage(layerContext, CGRectMake(10.0+x, 30.0+y, w, h), result.CGImage);
    //[self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
}

- (void)drawRect:(CGRect)rect 
{
  [m_image drawInRect:CGRectMake(10.0+x, 30.0+y, w, h)];
}
</code></pre>
