我有一个小应用程序,可以显示来自远程PC的屏幕。通常,为了提高性能,我们只更新正在更改的屏幕部分。这款应用可以正常工作,但当屏幕快速变化时,IPAD上的更新速度会非常慢。看看'dawrect‘和DoImage中的代码,我发现有很多代码是重复的,有什么方法可以优化它吗?
Thx
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
}
return self;
}
// Only override drawRect: if you perform custom drawing.
- (void)drawRect:(CGRect)rect {
CGColorSpaceRef color = CGColorSpaceCreateDeviceRGB();
context = CGBitmapContextCreate(offscreenPixels,1024,768,8,4*(1024),color,kCGImageAlphaPremultipliedLast);
UIGraphicsPushContext(context);
image = CGBitmapContextCreateImage(context);
UIGraphicsPopContext();
CGContextRelease(context);
CGColorSpaceRelease(color);
CGContextRef c=UIGraphicsGetCurrentContext();
CGContextDrawImage(c, CGRectMake(0, 0, 1024, 768), image);
CGImageRelease(image);
}
- (void)dealloc {
[super dealloc];
}
- (void)DoImage:(CGRect)rect theImage:(UIImage*)aImage {
CGColorSpaceRef color = CGColorSpaceCreateDeviceRGB();
context = CGBitmapContextCreate(offscreenPixels,1024,768,8,4*(1024),color,kCGImageAlphaPremultipliedLast);
UIGraphicsPushContext(context);
[aImage drawInRect:rect];
UIGraphicsPopContext();
CGContextRelease(context);
CGColorSpaceRelease(color);
// Rfresh screen
[self setNeedsDisplayInRect:rect];
}
发布于 2011-04-11 18:28:04
- (void)drawRect:(CGRect)rect {
[self doUpdateWithImage:image];
CGContextRef c=UIGraphicsGetCurrentContext();
CGContextDrawImage(c, CGRectMake(0, 0, 1024, 768), image);
CGImageRelease(image);
}
- (void)dealloc {
[super dealloc];
}
- (void)DoImage:(CGRect)rect theImage:(UIImage*)aImage {
[self doUpdateWithImage:aImage];
// Refresh screen
[self setNeedsDisplayInRect:rect];
}
- (void)doUpdateWithImage:(UIImage *)image
{
CGColorSpaceRef color = CGColorSpaceCreateDeviceRGB();
context = CGBitmapContextCreate(offscreenPixels,1024,768,8,4*(1024),color,kCGImageAlphaPremultipliedLast);
UIGraphicsPushContext(context);
image = CGBitmapContextCreateImage(context);
UIGraphicsPopContext();
CGContextRelease(context);
CGColorSpaceRelease(color);
}
希望能帮上点忙
https://stackoverflow.com/questions/5619854
复制相似问题