6
카메라 롤에서 이미지를로드하지만 이미지의 위아래가 뒤집습니다. 그래서 나는 그것을 회전시키는 방법을 썼다.이미지를 거꾸로 회전하지만 수평으로 뒤집는 방법
CGImageRef imageRef = [image CGImage];
float width = CGImageGetWidth(imageRef);
float height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
Byte *rawData = malloc(height * width * 4);
Byte bytesPerPixel = 4;
int bytesPerRow = bytesPerPixel * width;
Byte bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
int byteIndex = 0;
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
Byte *rawData2 = malloc(height * width * 4);
for (int i = 0 ; i < width * height ; i++) {
int index = (width * height) * 4;
rawData2[byteIndex + 0] = rawData[index - byteIndex + 0];
rawData2[byteIndex + 1] = rawData[index - byteIndex + 1];
rawData2[byteIndex + 2] = rawData[index - byteIndex + 2];
rawData2[byteIndex + 3] = rawData[index - byteIndex + 3];
byteIndex += 4;
}
CGContextRef ctx = CGBitmapContextCreate(rawData2, CGImageGetWidth(imageRef), CGImageGetHeight(imageRef), 8, CGImageGetBytesPerRow(imageRef), CGImageGetColorSpace(imageRef),kCGImageAlphaPremultipliedLast);
imageRef = CGBitmapContextCreateImage (ctx);
image = [UIImage imageWithCGImage:imageRef];
CGContextRelease(context);
return image;
괜찮아요,하지만 지금은 수평으로 뒤집어 야합니다. 어떻게해야 할 지 모르겠습니다. 나는이 두 번째 날을하려고 노력한다.
imageView.transform = CGAffineTransformMakeScale(-1, 1);
:
은이를 시도
나는 UIImage를 변형하고 CGContextRef에 그려야하므로'.transform'을 사용할 수 없습니다. 나는 UIImageView에 UIImage를 추가하고 회전시키고'image = imageView.image'를 만들려고 시도하지만 작동하지 않습니다. –
보기 내용을 이미지로 어떻게 "변환"할 수 있는지 편집하십시오. – sergio
작동하고 있지만'imageview.frame = CGRectMake (111,122,768,1024)'를 설정하고 컨텍스트를 '0,0,768,1024'로 렌더링합니다. 어떠한 제안? –