문제

자의 말을 찾으려면 이미지의 크기는 경우,그래서 그 사용자를 로드하려고 하면은 10,000x10,000 픽셀 이미지 내용할 수 있는 존재 그들과 대화과 충돌하지 유지하는 것입니다.내가 할 경우 [UIImage imageNamed:][UIImage imageWithContentsOfFile:] 는 것이드 잠재적으로 큰 이미지를 메모리로 즉시.

을 사용하면 핵심 이미지 대신 말하자면 다음과 같다:

CIImage *ciImage = [CIImage imageWithContentsOfURL:[NSURL fileURLWithPath:imgPath]];

다음 물을 내 새로운 CIImage 크기:

CGSize imgSize = ciImage.extent.size;

는 것을 로드하는 전체 이미지를 메모리에 저에게 이것을 말하거나,그것은 그냥 보는 메타데이터의 파일을 발견하는 크기의 이미지?

도움이 되었습니까?

해결책

imageWithContentsOfURL 기능 로드하는 이미지를 메모리,그렇습니다.

다행히 구현되는 애플 CGImageSource 읽기 위해 이미지 메타데이터를 로드하지 않고 실제 픽셀 데이터로 메모리에서 iOS4,당신은 당신에 대해 읽을 수 있습니다 그것을 사용하는 방법 이 블로그 게시물 (편리하게 제공하는 코드 샘플을 얻는 방법에 대한 이미지 크기).

편집:붙여하는 코드 샘플을 보호하기 위해 여기에 대한 링크를 부패:

#import <ImageIO/ImageIO.h>

NSURL *imageFileURL = [NSURL fileURLWithPath:...];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL);
if (imageSource == NULL) {
    // Error loading image
    ...
    return;
}

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                     [NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache,nil];
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)options);
if (imageProperties) {
    NSNumber *width = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
    NSNumber *height = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
    NSLog(@"Image dimensions: %@ x %@ px", width, height);
    CFRelease(imageProperties);
}

전체 API 를 참조 또한 여기에 사용할 수.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top