에 중복으로 표시 :부적절한 이미지 때문에 나는 이것에 대한 해결책을 찾을 수 없습니다 CGContext
나는 다른 이미지로 모두 2 개 이미지보기가 - IMAGE_1 (사람의 청바지) 및 IMAGE_2 (사람의 셔츠). 이제 image_1 또는 image_2의 RGB 값을 개별적으로 변경할 때마다 완벽한 결과를 얻습니다. 그러나 둘 중 하나가 내 프레임 중 하나를 처리 할 때마다 둘 다 처리 한 후 다른 프레임과 약간 겹치면 문제가 발생합니다. 도와주세요. 이것이 이미지를 처리하는 방법입니다.
-(UIImage *)ColorChangeProcessing :(int)redvalue greenValue:(int)greenvalue blueValue:(int)bluevalue imageUsed : (UIImage *)image
{
CGContextRef ctx;
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
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), imageRef);
CGContextRelease(context);
int byteIndex = (bytesPerRow * 0) + 0 * bytesPerPixel,RED = redvalue,GREEN=greenvalue,BLUE = bluevalue;
for (int ii = 0 ; ii < width * height ; ++ii)
{
if(rawData[byteIndex] != '/0' || rawData[byteIndex+1] != '/0' || rawData[byteIndex+2] != '/0'){
if ((((rawData[byteIndex])+RED)) > 255)
{
rawData[byteIndex] = (char)255;
}
else if((((rawData[byteIndex])+RED)) >0)
{
rawData[byteIndex] = (char) (((rawData[byteIndex] * 1.0) + RED));
}
else
{
rawData[byteIndex] = (char)0;
}
if ((((rawData[byteIndex+1])+GREEN)) > 255)
{
rawData[byteIndex+1] = (char)255;
}
else if((((rawData[byteIndex+1])+GREEN))>0)
{
rawData[byteIndex+1] = (char) (((rawData[byteIndex+1] * 1.0) + GREEN));
}
else
{
rawData[byteIndex+1] = (char)0;
}
if ((((rawData[byteIndex+2])+BLUE)) > 255)
{
rawData[byteIndex+2] = (char)255;
}
else if((((rawData[byteIndex+2])+BLUE))>0)
{
rawData[byteIndex+2] = (char) (((rawData[byteIndex+2] * 1.0) + BLUE));
}
else
{
rawData[byteIndex+2] = (char)0;
}
}
byteIndex += 4;
}
ctx = CGBitmapContextCreate(rawData,
CGImageGetWidth(imageRef),
CGImageGetHeight(imageRef),
8,
CGImageGetBytesPerRow(imageRef),
CGImageGetColorSpace(imageRef),
kCGImageAlphaPremultipliedLast);
CGImageRef NewimageRef = CGBitmapContextCreateImage (ctx);
UIImage* rawImage = [UIImage imageWithCGImage:NewimageRef];
CGContextRelease(ctx);
free(rawData);
CGImageRelease(NewimageRef);
return rawImage;
}
지금의 버튼 동작을하면 R, G, B 화상 & 값을 설정할 수 있고, 그 후 처리 된 화상을 얻는다. 그런 다음, 처리 된 이미지 프레임을 배치하여 한 이미지의 일부가 다른 이미지의 일부분을 차지하도록하십시오. 셔츠 이미지 위에 벨트 근처에 작은 부분을두기 만하면 청바지 이미지를 얻을 수 있습니다.
결과에 대한 스크린 샷이 있습니까? – Wain
스크린 샷을 게시했습니다. Plz 수표. – Vish
@wain 당신은 그 이미지를 겹쳐서 어떤 도움을 주실 수 있습니다 :) – Rushabh