2012-07-24 34 views
0

我有以下問題:如何掃描完整的圖像,以獲得它的每個像素的顏色。iphone - 掃描完成圖像的像素顏色

我使用此庫https://github.com/unixpickle/ANImageBitmapRep

我有這樣的代碼:

- (void)executeImageScanProcessWithImage:(UIImage *)image{ 


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 
             (unsigned long)NULL), ^(void) { 


    NSString *rowString = @""; 
    NSMutableArray *array = [[NSMutableArray alloc] init]; 
    ANImageBitmapRep *imageBitmap; 
    UIColor *color; 
    // Loop für die Spalten (y) 
    for (int y = 0; y < 320; y += 20) { 
     rowString = @""; // rowString zurücksetzen 

     // Loop für die Reihe (x) 
     for (int x = 0; x < image.size.width; x += 20) { 

      BMPoint pixelPoint = BMPointMake(x, y); 
      imageBitmap = [ANImageBitmapRep imageBitmapRepWithImage:image]; 
      BMPixel pixel = [imageBitmap getPixelAtPoint:pixelPoint]; 
      color = UIColorFromBMPixel(pixel); 

      if ([color isEqual:[UIColor redColor]]) { 
       rowString = [rowString stringByAppendingFormat:@"0"]; 
      } 
      else { 
       rowString = [rowString stringByAppendingFormat:@"1"]; 
      } 

      // Wenn der letzte "Run" vollzogen ist, wird die rowString in den Array hinzugefügt 
      if ([rowString length] == image.size.width/20) { 
       [array addObject:rowString]; 
      } 
     } 

     [array addObject:rowString]; 
    } 

    NSLog(@"content of array = %@",array); 


}); 

}

的問題是,我得到這個錯誤,當圖像變得太大。

Malloc失敗了,這太糟糕了。我希望能夠使用這個記憶。七月 24 18點31分41秒信徒-的MacBook-Pro.local Bitmap_Test [2374]: CGBitmapContextGetData:無效的上下文爲0x0 7月24日18時31分41秒 信徒-的MacBook-Pro.local Bitmap_Test [2374]: CGBitmapContextCreateImage:無效上下文爲0x0 7月24日18點31分41秒 信徒-的MacBook-Pro.local Bitmap_Test [2374]: CGBitmapContextGetWidth:無效的上下文爲0x0 Bitmap_Test(2374,0xb0103000)malloc的:* MMAP(大小= 2265088)失敗 (錯誤代碼= 12)

你知道另一種方法來處理這個計劃嗎?來自德國

最好的問候, 克里斯

回答