나는 이미지를 미러링 할 수있는 방법이 있는지 알아 내려고하고 있습니다. 예를 들어, 누군가의 얼굴 사진을 찍은 다음 반으로 자르고 각면이 거울처럼 보일 때 얼굴이 어떻게 보이는지 보여줍니다. CGAffineTransform 함수에서 이와 같은 트릭이없는 것 같습니다. 그래픽 전문가가 도와주세요!어떻게하면 UIImagePickerController에서 UIImage 그림을 미러링합니까
답변
여기서 기본 "트릭"은 X 축 또는 Y 축에 대한 배율 변환을 -1 배수로 사용하는 것입니다.
CGAffineTransform transform = CGAffineTransformScale(transform, -1, 1);
이 그럼 당신은 할당 된 이미지를 뒤집을 수있는 UIImageView
에 transform
속성을 설정하거나 할 변환 서로를 연결하여 예를 들어, "수평 축에 대한 플립"을 만들려면이 사용할 수 변환 보다 정교한 효과. 기술 한 정확한 효과를 얻으려면 원본 이미지를 컨텍스트에 그리는 사용자 지정 드로잉 코드를 작성한 다음 반전 된 반을 위에 오버레이해야 할 수 있습니다. 이것은 Core Graphics에서 비교적 간단합니다.
경우에만 않을까 긴 switch 문 귀찮게 왜 4.0 이상
UIImageOrientation flippedOrientation = UIImageOrientationUpMirrored;
switch (image.imageOrientation) {
case UIImageOrientationUp: break;
case UIImageOrientationDown: flippedOrientation = UIImageOrientationDownMirrored; break;
// ...
}
UIImage * flippedImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:flippedOrientation];
당신은 생각을, 지원 계획이라면?
? UIImage *flip = [UIImage imageWithCGImage:image.CGImage
? scale:image.scale
? orientation:(image.imageOrientation + 4) % 8];
그리고 당신은 열거를 살펴 경우는 모듈러 산술 할 것이라고 볼 수
이typedef NS_ENUM(NSInteger, UIImageOrientation) {
UIImageOrientationUp, // default orientation
UIImageOrientationDown, // 180 deg rotation
UIImageOrientationLeft, // 90 deg CCW
UIImageOrientationRight, // 90 deg CW
UIImageOrientationUpMirrored, // as above but image mirrored along other axis. horizontal flip
UIImageOrientationDownMirrored, // horizontal flip
UIImageOrientationLeftMirrored, // vertical flip
UIImageOrientationRightMirrored, // vertical flip
};
그러나이 코드는 너무 영리하다. 대신 명시적인 switch 문을 사용하여 함수를 작성해야합니다. 예 :
UIImageOrientation mirroredImageOrientation(UIImageOrientation orientation) {
switch(orientation) {
case UIImageOrientationUp: return UIImageOrientationUpMirrored;
case UIImageOrientationDown: return UIImageOrientationDownMirrored;
case UIImageOrientationLeft: return UIImageOrientationLeftMirrored;
case UIImageOrientationRight: return UIImageOrientationRightMirrored;
case UIImageOrientationUpMirrored: return UIImageOrientationUp;
case UIImageOrientationDownMirrored: return UIImageOrientationDown;
case UIImageOrientationLeftMirrored: return UIImageOrientationLeft;
case UIImageOrientationRightMirrored: return UIImageOrientationRight;
default: return orientation;
}
}
그리고이 같은 기능을 사용 : 내가 의심, 냄새 나는 코드를 나타 내기 위해 물음표를 추가 한
UIImage *flip = [UIImage imageWithCGImage:image.CGImage
scale:image.scale
orientation:mirroredImageOrientation(image.imageOrientation)];
실제로 응답이 좋으면 모든 경우가 아닙니다. 예 : 수평 뒤집기를하고 싶지만 이미지 방향이 맞다면 LeftMirrored를해야합니다. RightMirrored가 수직 뒤집기를하게됩니다. – AncAinu
미러되지 않은 미러에서 미러 된 미러로 이동하면 자리에 앉아있는 사람의 관점에서 이미지가 수평으로 대칭됩니다. 이미지 자체의 관점에서 보면 열거 형의 주석에 따라 뒤집을 것입니다.면이 올바른 방향 (이미지의 맨 위부터 맨 위)으로 향한 경우 미러되지 않은 이미지에서부터 미러링하면 해당면을 수평으로 (즉, 수직 축을 따라) 뒤집을 수 있습니다. UIImageOrientation에 대한 문서 : https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/#//apple_ref/c/tdef/UIImageOrientation. – sabalaba
나는 내 대답을 편집하여 명시적인 switch 문을 사용하도록 제안했습니다. 길 아래에서 어떤 일이 일어날 지 누가 알겠습니까? 어쩌면 애플은 열거 형의 순서를 변경하여 모듈러 산술 버전이 부정확해질 수 있습니다. – sabalaba
위의 답변 중 아무 것도 이미지 전체를 뒤집지 않는 이미지의 절반을 반영하는 부분에 응답하십시오.
(UIImage *) horizontalMirror {
UIImageOrientation flippedOrientation = UIImageOrientationUpMirrored;
switch (self.imageOrientation) {
case UIImageOrientationUp: break;
case UIImageOrientationDown: flippedOrientation = UIImageOrientationDownMirrored; break;
}
UIImage * flippedImage = [UIImage imageWithCGImage:self.CGImage scale:1.0 orientation:flippedOrientation];
CGImageRef inImage = self.CGImage;
CGContextRef ctx = CGBitmapContextCreate(NULL,
CGImageGetWidth(inImage),
CGImageGetHeight(inImage),
CGImageGetBitsPerComponent(inImage),
CGImageGetBytesPerRow(inImage),
CGImageGetColorSpace(inImage),
CGImageGetBitmapInfo(inImage)
);
CGRect cropRect = CGRectMake(flippedImage.size.width/2, 0, flippedImage.size.width/2, flippedImage.size.height);
CGImageRef TheOtherHalf = CGImageCreateWithImageInRect(flippedImage.CGImage, cropRect);
CGContextDrawImage(ctx, CGRectMake(0, 0, CGImageGetWidth(inImage), CGImageGetHeight(inImage)), inImage);
CGAffineTransform transform = CGAffineTransformMakeTranslation(flippedImage.size.width, 0.0);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
CGContextConcatCTM(ctx, transform);
CGContextDrawImage(ctx, cropRect, TheOtherHalf);
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return finalImage;
}
고마워요. – ChanWarde
- 1. UIImagePickerController에서 UIButton에 UIImage 추가하기
- 2. iPhone에서 덤프 UIImage
- 3. UIWebView에서 카메라의 UIImage 표시
- 4. UIImagePickerController에서 결과를 자르기위한 cameraOverlayView
- 5. UIImagePickerController에서 방향 변경 감지?
- 6. UIImagepickerController에서 영화 URL 얻기
- 7. UIImagePickerController에서 비디오 저장하기
- 8. UIPinchGestureRecognizer로지도의 그림을 어떻게 스케일링해야합니까?
- 9. 배경 처리를 위해 UIImagePickerController에서 이미지 데이터를 전달합니다.
- 10. 내 개발 환경이 사용자 환경을 미러링합니까?
- 11. UIImage *는 UIImage 대신 __NSCFArray입니다.
- 12. UIImagePickerController에서 비디오 캡처를 비활성화하는 방법
- 13. UIImagePickerController에서 URL을 가져 오는 방법
- 14. 나중에 UIImagePickerController에서 비디오를 압축 하시겠습니까?
- 15. UIImage Not Transparent
- 16. drawInRect를 사용하여 UIImage
- 17. UIImage animation
- 18. UIImage 비교
- 19. UIImage imageWithData
- 20. CGRect있는 UIImage
- 21. Uiimage Imagenamed
- 22. 움직이는 그림을
- 23. matplotlib 그림을 복사하는 방법은 무엇입니까?
- 24. iPhone 라이브러리의 UIImagePickerController에서 버튼을 선택하는 방법
- 25. UIImagePickerController에서 선택한 비디오의 크기를 가져 오기
- 26. UIImagePickerController에서 "취소"버튼을 제거 할 수 있습니까?
- 27. NSUserDefaults를 통해 iPhone 메모리에 UIImage 저장
- 28. URL에서 그림을 추가하는 데 도움이 필요합니다.
- 29. UIImage - 어떻게 색인을 추적합니까?
- 30. uiimage oncomplete iphone
또는 CGAffineTransformMakeScale 즉 picker.cameraViewTransform = CGAffineTransformMakeScale 사용 (-1, 1) // SWIFT – khunshan
우수 : 용액을 혼합하면 예를 UIImage + 미러링 카테고리로 사용할 수있는 다음 샘플 함수 리드! 'myImageView.transform = CGAffineTransformMakeScale (-1, 1); '을 사용했습니다. –