UIImage를 반으로 나누면 (중간 아래) 두 이미지를 만들 수 있습니까?UIImage를 절반으로 분할 했습니까?
8
A
답변
19
,
UIImage *image = [UIImage imageNamed:@"yourImage.png"];
CGImageRef tmpImgRef = image.CGImage;
CGImageRef topImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(0, 0, image.size.width, image.size.height/2.0));
UIImage *topImage = [UIImage imageWithCGImage:topImgRef];
CGImageRelease(topImgRef);
CGImageRef bottomImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(0, image.size.height/2.0, image.size.width, image.size.height/2.0));
UIImage *bottomImage = [UIImage imageWithCGImage:bottomImgRef];
CGImageRelease(bottomImgRef);
희망이 당신을 도울 수, :)
0
다른 질문 Stackoverflow 질문 당신이 시도 할 수 Source
UIImage *splitMeInTwo = [UIImage imageNamed:@"Star.png"];
UIImageView *original = [[UIImageView alloc] initWithImage:splitMeInTwo];
[self.view addSubview:original];
[original release];
// The size of each part is half the height of the whole image
CGSize size = CGSizeMake([splitMeInTwo size].width, [splitMeInTwo size].height/2);
// Create image-based graphics context for top half
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
// Draw into context, bottom half is cropped off
//[image drawAtPoint:CGPointMake(0.0,0.0)];
[splitMeInTwo drawAtPoint:CGPointMake(0.0,0.0) blendMode:kCGBlendModeNormal alpha:1.0];
// Grab the current contents of the context as a UIImage
// and add it to our array
UIImage *top = UIGraphicsGetImageFromCurrentImageContext();
UIImageView *topV = [[UIImageView alloc] initWithImage:top];
CGRect frameTop = topV.frame;
frameTop.origin.x += 360.0f;
topV.frame = frameTop;
[self.view addSubview:topV];
[topV release];
UIGraphicsEndImageContext();
5
- (void)splitImage:(UIImage *)image
{
CGFloat imgWidth = image.size.width/2;
CGFloat imgheight = image.size.height;
CGRect leftImgFrame = CGRectMake(0, 0, imgWidth, imgheight);
CGRect rightImgFrame = CGRectMake(imgWidth, 0, imgWidth, imgheight);
CGImageRef left = CGImageCreateWithImageInRect(image.CGImage, leftImgFrame);
CGImageRef right = CGImageCreateWithImageInRect(image.CGImage, rightImgFrame);
// These are the images we want!
UIImage *leftImage = [UIImage imageWithCGImage:left];
UIImage *rightImage = [UIImage imageWithCGImage:right];
// Don't forget to free the memory!
CGImageRelease(left);
CGImageRelease(right);
}
+0
이것은 전체 컨텍스트를 생성하지 않는 유일한 대답입니다. Quartz는 자르기 과정을 최적화 할 때 새로운 컨텍스트 만들기, 이미지 그리기, 자르기 대신 이미지의 픽셀 데이터를 바로 가져 오는 작업을 훌륭하게 수행합니다. 이미지를 여러 개의 작은 부분으로 나누면 잠재적으로 여러 번 더 빨라집니다! –
0
아이폰 OS (11), 신속한 4.0 솔직히 생각 버전 https://stackoverflow.com/users/893872/durul-dalkanat이 업데이트 된 최고 :
이렇게하면 이미지가 4 부분으로 나뉩니다.
func splitImage(image2D: UIImage) -> [UIImage] {
let imgWidth = image2D.size.width/2
let imgHeight = image2D.size.height/2
var imgImages:[UIImage] = []
let leftHigh = CGRect(x: 0, y: 0, width: imgWidth, height: imgHeight)
let rightHigh = CGRect(x: imgWidth, y: 0, width: imgHeight, height: imgHeight)
let leftLow = CGRect(x: 0, y: imgHeight, width: imgWidth, height: imgHeight)
let rightLow = CGRect(x: imgWidth, y: imgHeight, width: imgWidth, height: imgHeight)
let leftQH = image2D.cgImage?.cropping(to:leftHigh)
let rightHQ = image2D.cgImage?.cropping(to:rightHigh)
let leftQL = image2D.cgImage?.cropping(to:leftLow)
let rightQL = image2D.cgImage?.cropping(to:rightLow)
imgImages.append(UIImage(cgImage: leftQH!))
imgImages.append(UIImage(cgImage: rightHQ!))
imgImages.append(UIImage(cgImage: leftQL!))
imgImages.append(UIImage(cgImage: rightQL!))
return imgImages
}
관련 문제
- 1. 파일을 세그먼트로 분할 했습니까?
- 2. 큰 UIImage를 텍스처 용으로 분할 사용
- 3. lfind에서 분할 오류가 발생 했습니까?
- 4. MapView를 화면 절반으로 제한
- 5. 구분 기호를 기준으로 열 값을 분할 했습니까?
- 6. opendir()을 사용하여 분할 오류가 발생 했습니까?
- 7. JSplitPane - 응용 프로그램을 두 개로 분할 했습니까?
- 8. 파이썬에서 KIO로 분할 오류가 발생 했습니까?
- 9. 자식 분기를 두 개의 분기로 분할 했습니까?
- 10. UIImage를 다른 색으로 착색하거나 벡터에서 UIImage를 생성합니다.
- 11. TSQL에서 절반으로 분할 쿼리 결과 (2 개의 결과 집합/테이블 확보)
- 12. Facebook의 버튼 댓글 팝업 창이 절반으로 표시됩니다.
- 13. wrap_content height, parent 부모의 절반으로 제한
- 14. 바이트 배열 크기를 원래 크기의 절반으로 줄이려면
- 15. "신호 분할 오류". 이 오류는 어디서 발생 했습니까? 때때로
- 16. 파일을 열거 나 닫을 때 분할 오류가 발생 했습니까?
- 17. PHP : 배열을 사용자 정의 함수를 기반으로하는 청크로 분할 했습니까?
- 18. 콘텐츠 (CMS)와 기능을 별도의 웹 사이트로 분할 했습니까?
- 19. 큰 웹 프로젝트를 만들거나 일부 기능을 웹 서비스로 분할 했습니까?
- 20. Perl은 가장 효율적인 방식으로 반복 패턴에 문자열을 분할 했습니까?
- 21. 색상별로 UIImage를 분할하고 2 개의 이미지를 만듭니다.
- 22. NMAP XML 파일 분할
- 23. iPhone : 반복 가능한 UIImage를 확장하는 방법?
- 24. Java 텍스트 분할 알고리즘
- 25. UIImageView에서 UIImage를 삭제하는 방법?
- 26. UIImage를 압축하는 방법은 무엇입니까?
- 27. UIImage를 PDF 파일로 변환
- 28. UITextView에 UIImage를 추가하는 방법
- 29. UIImage를 효율적으로 사용합니까?
- 30. 포인트에서 UIImage를 만듭니다.
큰 활약을했습니다. 감사! – Shredder2794