objective c:将图像像素RGB值保存到Array

时间:2021-05-08 13:20:32

I'm trying some experimental imagestuff on ipad and I'm trying to store every pixel's colordata into one array to increase performance for reading every pixel colordata,

我在ipad上尝试一些实验图像,我试图将每个像素的colordata存储到一个数组中,以提高读取每个像素colordata的性能,

right now I have a timer that calls my DrawRect as much as possible, in my DrawRect function I have this:

现在我有一个尽可能多地调用我的DrawRect的计时器,在我的DrawRect函数中我有这个:

-(void)drawRect:(CGRect)rect
{
    UIGraphicsBeginImageContext(self.frame.size);
    [currentImage.image drawInRect:CGRectMake(0, 0, 768, 1004)];
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 0.3);  

    r_x = r_x + 1;

    if (r_x == 768) {
        r_x = 1;
        r_y = r_y + 1;
    }
    if (r_y == 1004) {
        NSLog(@"color = %@", mijnArray_kleur);
    }
    CGPoint point2_1 = CGPointMake(r_x, r_y);
    GetColor *mycolor = [GetColor alloc];
    UIColor *st = [mycolor getPixelColorAtLocation:point2_1];
    [mijnArray_kleur addObject:st];
    [mycolor release];
    CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [st CGColor]);

    CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(r_x,r_y,1,1));
}

and getPixelColorAtLocation is a custom class that returns the UIDeviceRGBColorSpace values of a pixel

和getPixelColorAtLocation是一个自定义类,它返回像素的UIDeviceRGBColorSpace值

with this it takes me about 4 hours (yes, hours :p) to complete one image, is there anything faster/improvements?

有了它,我需要大约4个小时(是的,小时:p)来完成一个图像,有什么更快/改进吗?

Thanks!

谢谢!

Thys

蒂斯

1 个解决方案

#1


4  

[Copied from comment for clarity] Not that I know objective C, at all, but it seems to me like your function iterates over 768 * 1004 values and thus draws that many rectangles. Guessing about 60 frames/second, this would take 3h 40min. Am I wrong here?

[为澄清而复制评论]并不是说我知道目标C,但在我看来,你的函数迭代超过768 * 1004的值,从而绘制了许多矩形。猜测大约60帧/秒,这需要3小时40分钟。我错了吗?

#1


4  

[Copied from comment for clarity] Not that I know objective C, at all, but it seems to me like your function iterates over 768 * 1004 values and thus draws that many rectangles. Guessing about 60 frames/second, this would take 3h 40min. Am I wrong here?

[为澄清而复制评论]并不是说我知道目标C,但在我看来,你的函数迭代超过768 * 1004的值,从而绘制了许多矩形。猜测大约60帧/秒,这需要3小时40分钟。我错了吗?