CGImageSourceCreateThumbnailAtIndex
에 제공된 옵션에서 키 kCGImageSourceCreateThumbnailWithTransform
에 값 (kCFBooleanTrue)을 제공하고 전체 이미지의 방향 및 픽셀 종횡비에 따라 축소판을 회전하고 비율을 조정해야합니다.
이
당신은 당신이
카테고리 사용
ImageIO에서 그것을 크기를 조정할 수있는 UIImage에 추가 된 크기 대신 원하는 최대 값을 제공하기 위해이 구현을 수정할 수 있습니다이 키
/* Specifies whether the thumbnail should be rotated and scaled according
* to the orientation and pixel aspect ratio of the full image. The value
* of this key must be a CFBooleanRef; the default value of this key is
* kCFBooleanFalse. */
IMAGEIO_EXTERN const CFStringRef kCGImageSourceCreateThumbnailWithTransform IMAGEIO_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_4_0);
의 문서입니다
UIImage + Resizing.h
#import <UIKit/UIKit.h>
@interface UIImage (Resizing)
-(UIImage*)resizedImageWithData:(NSData*)imageData withSize:(CGSize)size;
@end
UIImage + Re 크기 조정.
#import "UIImage+Resizing.h"
#import <ImageIO/ImageIO.h>
@implementation UIImage (Resizing)
-(UIImage*)resizedImageWithData:(NSData*)imageSource withSize:(CGSize)size{
// Resizing Using ImageIO
CGImageSourceRef src = CGImageSourceCreateWithData((__bridge CFDataRef)imageSource, nil);
// load the image at the desired size
NSDictionary* options = @{
(id)kCGImageSourceShouldAllowFloat: (id)kCFBooleanTrue,
(id)kCGImageSourceCreateThumbnailWithTransform: (id)kCFBooleanTrue,
(id)kCGImageSourceCreateThumbnailFromImageAlways: (id)kCFBooleanTrue,
(id)kCGImageSourceThumbnailMaxPixelSize: @((int)(size.width > size.height ? size.width : size.height))
};
CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(src, 0, (__bridge CFDictionaryRef)options);
if (NULL != src)
CFRelease(src);
UIImage* scaledImage = [UIImage imageWithCGImage:imageRef];
if (NULL != imageRef)
CFRelease(imageRef);
return scaledImage;
}
@end
고맙지 만 물론 나는 그것을 봤습니다. 그렇습니다. 수많은 방법이 있습니다. 제 질문은 어떤 방식 으로든 CGImageSourceCreateThumbnailAtIndex를 사용하여 수행 할 수 있다는 것입니다. –