0

我想在我的 UIIMage 上再画 1 条线,现在我这样做:

-(void)drawRect
{


    UIGraphicsBeginImageContext(myImage.size);


    code to draw line on current context...

    draw previous info from myImage:
    [myImage drawInRect:myRect];

    //store info from context back to myImage
    myImage=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();


    //append the image on the right side of current context:
    [myImage drawInRect:myRightRect];
}

问题是我认为每次只为增加 1 行绘制整个图像非常昂贵,有人知道如何优化它吗?

4

1 回答 1

0

好的,没有人回答,但这是我找到的解决方案:

  1. 首先创建位图上下文:

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    
    
    CGContextRef bitmapContext = CGBitmapContextCreate (NULL, pixelsWide, pixelsHigh, 8,
                                                    0, colorSpace,(kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
    CGColorSpaceRelease(colorSpace);
    
  2. 在此上下文中绘制线条和形状。

  3. 现在通过使用以下方法将上下文中的信息返回到 bitamp 图像中:

    CGImageRef leftScaleImage = CGBitmapContextCreateImage(bitmapContext);
    UIImage* leftScaleUIImage = [UIImage imageWithCGImage:leftScaleImage];
    

干杯!

于 2013-11-28T12:24:06.187 回答