3
색상이 객체로 배열되어 있습니다. 나는 그것에서 이미지를 만들고 싶다. 사실, 무슨 일이 일어나고, 나는 이미지의 각 픽셀의 픽셀 값을 가져 와서 수정하고 해당 객체를 변경할 수있는 배열에 저장합니다. 이제 이것으로 이미지를 그려야합니다. 그렇게하는 방법?? 어떤 아이디어?iphone에서 색상 배열로 이미지 만들기
-(UIImage*)modifyPixels:(UIImage*)originalImage {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSMutableArray *result =[[NSMutableArray alloc]init];
int width = img.size.width;
int height = img.size.height;
originalImage = imageView.image;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc (height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height),img.CGImage);
CGContextRelease(context);
int byteIndex = 0;
for (int xx=0;xx<width;xx++){
for (int yy=0;yy<height;yy++){
// Now rawData contains the image data in the RGBA8888 pixel format.
NSLog(@"(%d,%d)",xx,yy);
NSLog(@"Alpha 255-Value is: %u", rawData[byteIndex + 3]);
NSLog(@"Red 255-Value is: %u", rawData[byteIndex]);
NSLog(@"Green 255-Value is: %u",rawData[byteIndex + 1]);
NSLog(@"Blue 255-Value is: %u",rawData[byteIndex + 2]);
CGFloat red = (rawData[byteIndex]+rawData[byteIndex + 1]+rawData[byteIndex + 2])/3;
CGFloat green = red;
CGFloat blue = red;
CGFloat alpha = 255;
byteIndex += 4;
UIColor *acolor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
[result addObject:acolor];
}
}
UIImage *newImage;
//CREATE NEW UIIMAGE (newImage) HERE from acolor(array of colors)
//this is the portion i'm in trouble with
return newImage;
[pool release];
}
[풀 릴리스]는 도달 할 수없는 코드이며 누수가 발생합니다. 어쨌든 메서드는 자체 풀이 필요하지 않습니다. Xcode 프로젝트에서 Clang 정적 분석 도구를 사용할 수도 있습니다. (그룹 트리에서 프로젝트의 '정보 입수 ->'정적 분석 실행 ') –