English 中文(简体)
借助大型紫外线进行的核心分类
原标题:CoreGraphics drawing on a large UIImage

我有一幅“UIImage”一线,沿用用户指指的。 它就像一个绘画板。 当UIImage公司规模不大,即500×600,但如果它像1600×1200一样,它实际上已经rat忙和滞后。 我能否以最佳方式做到这一点? 这是我的引人注意的法典:

UIGraphicsBeginImageContext(self.frame.size);
[drawImageView.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
//CGContextSetAlpha(UIGraphicsGetCurrentContext(), 0.5f);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

感谢。

问题回答

不要把整个1600X1200框架单行,为什么不按需要加以利用。 我指的是,由于你正在设计整个框架(记忆中),你正在patch业。

Try CATiled Layer。 基本上,你需要只抽出能够使用你的装置的屏幕尺寸,而其程度要大于用户需要从中提取的镜头。

This is what is used in Google Maps on iPad or iPhone. Hope this helps...

无论何时发生触动,都不会创造新的环境,把目前的形象带入其中,而是利用 地图/Create<>/code”和再利用这一背景。 以前的所有绘画都将是这样,每当感动时,你们就不得不创造新的环境。

- (CGContextRef)drawingContext {
    if(!context) { // context is an instance variable of type CGContextRef
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        if(!colorSpace) return nil;
        context = CGBitmapContextCreate(NULL, contextSize.width, contextSize.height,
                                        8, contextSize.width * 32, colorSpace,
                                        kCGImageAlphaPremultipliedFirst);
        CGColorSpaceRelease(colorSpace);
        if(!context) return nil;
        CGContextConcatCTM(context, CGAffineTransformMake(1,0,0,-1,0,contextSize.height));
        CGContextDrawImage(context, (CGRect){CGPointZero,contextSize}, drawImageView.image.CGImage);
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15.0);
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
    }
    return context;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    CGContextRef ctxt = [self drawingContext];
    CGContextBeginPath(ctxt);
    CGContextMoveToPoint(ctxt, lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(ctxt, currentPoint.x, currentPoint.y);
    CGContextStrokePath(ctxt);
    CGImageRef img = CGBitmapContextCreateImage(ctxt);
    drawImageView.image = [UIImage imageWithCGImage:img];
    CGImageRelease(img);
}

该代码要求示例变量CGContextRef contextCGSize contextSize。 情况需要释放,只要你改变规模。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签