gpt4 book ai didi

iphone - 代码优化

转载 作者:行者123 更新时间:2023-11-28 17:46:36 25 4
gpt4 key购买 nike

我有一个小应用程序可以显示来自远程 PC 的屏幕。通常为了提高性能,我们只更新屏幕中发生变化的部分。该应用程序可以运行,但是当屏幕快速变化时,IPAD 上的更新非常慢。查看“dawrect”和 DoImage 中的代码,我看到很多重复的代码,有什么方法可以优化它吗?

谢谢

- (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];
}

最佳答案

- (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);
}

希望能帮到你

关于iphone - 代码优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5619854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com