programing

UI 이미지:크기 조정 후 자르기

lovejava 2023. 7. 3. 22:28

UI 이미지:크기 조정 후 자르기

저는 말 그대로 며칠 동안 이것에 얼굴을 박고 있었고 제가 계속해서 폭로 직전에 있다고 느끼지만, 저는 제 목표를 달성할 수 없습니다.

저는 제 디자인의 개념적인 단계에서 미리 아이폰의 카메라나 라이브러리에서 이미지를 가져와서 UIImageView의 Aspect Fill 옵션과 동일한 기능(전체 코드)을 사용하여 지정된 높이로 축소한 다음 통과된 CGRect에 맞지 않는 모든 것을 잘라내는 것은 사소한 문제라고 생각했습니다.

카메라나 라이브러리에서 원본 이미지를 가져오는 것은 사소한 일이었습니다.저는 다른 두 단계가 얼마나 어려운 것으로 판명되었는지에 충격을 받았습니다.

첨부된 이미지는 제가 성취하고자 하는 것을 보여줍니다.누가 제 손 좀 잡아 주시겠어요?제가 지금까지 찾은 모든 코드 예제는 이미지를 부수거나, 뒤집히거나, 쓰레기처럼 보이거나, 범위를 벗어나거나, 아니면 제대로 작동하지 않는 것 같습니다.

저도 같은 것이 필요했습니다. 제 경우에는 한 번 축척된 크기에 맞는 치수를 선택한 다음 나머지 부분을 너비에 맞게 자릅니다. (저는 조경 작업을 하고 있기 때문에 세로 모드의 결함을 알아차리지 못했을 수도 있습니다.)여기 제 코드가 있습니다. UI 이미지의 범주에 포함되어 있습니다.내 코드의 대상 크기는 항상 장치의 전체 화면 크기로 설정됩니다.

@implementation UIImage (Extras)

#pragma mark -
#pragma mark Scale and crop image

- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
{
    UIImage *sourceImage = self;
    UIImage *newImage = nil;    
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);

    if (CGSizeEqualToSize(imageSize, targetSize) == NO) 
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;

        if (widthFactor > heightFactor) 
        {
            scaleFactor = widthFactor; // scale to fit height
        }
        else
        {
            scaleFactor = heightFactor; // scale to fit width
        }

        scaledWidth  = width * scaleFactor;
        scaledHeight = height * scaleFactor;

        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5; 
        }
        else
        {
            if (widthFactor < heightFactor)
            {
                thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
            }
        }
    }   

    UIGraphicsBeginImageContext(targetSize); // this will crop

    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width  = scaledWidth;
    thumbnailRect.size.height = scaledHeight;

    [sourceImage drawInRect:thumbnailRect];

    newImage = UIGraphicsGetImageFromCurrentImageContext();

    if(newImage == nil)
    {
        NSLog(@"could not scale image");
    }

    //pop the context to get back to the default
    UIGraphicsEndImageContext();

    return newImage;
}

이전 게시물에는 UI 이미지 크기를 조정하는 방법에 대한 코드가 포함되어 있습니다.관련 부분은 다음과 같습니다.

+ (UIImage*)imageWithImage:(UIImage*)image 
               scaledToSize:(CGSize)newSize;
{
   UIGraphicsBeginImageContext( newSize );
   [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
   UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();

   return newImage;
}

자르기에 관한 한, 저는 스케일링에 대해 컨텍스트에 대해 다른 크기를 사용하도록 방법을 변경하면 결과 이미지가 컨텍스트의 경계에 맞게 클리핑되어야 한다고 생각합니다.

+ (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)targetSize {
    //If scaleFactor is not touched, no scaling will occur      
    CGFloat scaleFactor = 1.0;

    //Deciding which factor to use to scale the image (factor = targetSize / imageSize)
    if (image.size.width > targetSize.width || image.size.height > targetSize.height)
        if (!((scaleFactor = (targetSize.width / image.size.width)) > (targetSize.height / image.size.height))) //scale to fit width, or
            scaleFactor = targetSize.height / image.size.height; // scale to fit heigth.

    UIGraphicsBeginImageContext(targetSize); 

    //Creating the rect where the scaled image is drawn in
    CGRect rect = CGRectMake((targetSize.width - image.size.width * scaleFactor) / 2,
                             (targetSize.height -  image.size.height * scaleFactor) / 2,
                             image.size.width * scaleFactor, image.size.height * scaleFactor);

    //Draw the image into the rect
    [image drawInRect:rect];

    //Saving the image, ending image context
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return scaledImage;
}

저는 이것을 제안합니다.그녀는 아름답지 않나요?;)

이미지 크기 조정 및 기타 여러 작업과 관련된 훌륭한 코드가 있습니다.이미지 크기를 조정하는 방법을 찾다가 이 문제를 발견했습니다.http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

이것은 Jane Sales의 Swift 답변 버전입니다.건배!

public func resizeImage(image: UIImage, size: CGSize) -> UIImage? {
    var returnImage: UIImage?

    var scaleFactor: CGFloat = 1.0
    var scaledWidth = size.width
    var scaledHeight = size.height
    var thumbnailPoint = CGPointMake(0, 0)

    if !CGSizeEqualToSize(image.size, size) {
        let widthFactor = size.width / image.size.width
        let heightFactor = size.height / image.size.height

        if widthFactor > heightFactor {
            scaleFactor = widthFactor
        } else {
            scaleFactor = heightFactor
        }

        scaledWidth = image.size.width * scaleFactor
        scaledHeight = image.size.height * scaleFactor

        if widthFactor > heightFactor {
            thumbnailPoint.y = (size.height - scaledHeight) * 0.5
        } else if widthFactor < heightFactor {
            thumbnailPoint.x = (size.width - scaledWidth) * 0.5
        }
    }

    UIGraphicsBeginImageContextWithOptions(size, true, 0)

    var thumbnailRect = CGRectZero
    thumbnailRect.origin = thumbnailPoint
    thumbnailRect.size.width = scaledWidth
    thumbnailRect.size.height = scaledHeight

    image.drawInRect(thumbnailRect)
    returnImage = UIGraphicsGetImageFromCurrentImageContext()

    UIGraphicsEndImageContext()

    return returnImage
}

여기 있어요.이것은 완벽합니다 ;-)

편집: 아래 설명을 참조하십시오. "특정 이미지에서 작동하지 않습니다. 다음 오류로 실패합니다. CGC ContextSetInterpolationQuality: 잘못된 컨텍스트 0x0 오류"

// Resizes the image according to the given content mode, taking into account the image's orientation
- (UIImage *)resizedImageWithContentMode:(UIViewContentMode)contentMode imageToScale:(UIImage*)imageToScale bounds:(CGSize)bounds interpolationQuality:(CGInterpolationQuality)quality {
    //Get the size we want to scale it to
    CGFloat horizontalRatio = bounds.width / imageToScale.size.width;
    CGFloat verticalRatio = bounds.height / imageToScale.size.height;
    CGFloat ratio;

    switch (contentMode) {
        case UIViewContentModeScaleAspectFill:
            ratio = MAX(horizontalRatio, verticalRatio);
            break;

        case UIViewContentModeScaleAspectFit:
            ratio = MIN(horizontalRatio, verticalRatio);
            break;

        default:
            [NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
    }

    //...and here it is
    CGSize newSize = CGSizeMake(imageToScale.size.width * ratio, imageToScale.size.height * ratio);


    //start scaling it
    CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
    CGImageRef imageRef = imageToScale.CGImage;
    CGContextRef bitmap = CGBitmapContextCreate(NULL,
                                                newRect.size.width,
                                                newRect.size.height,
                                                CGImageGetBitsPerComponent(imageRef),
                                                0,
                                                CGImageGetColorSpace(imageRef),
                                                CGImageGetBitmapInfo(imageRef));

    CGContextSetInterpolationQuality(bitmap, quality);

    // Draw into the context; this scales the image
    CGContextDrawImage(bitmap, newRect, imageRef);

    // Get the resized image from the context and a UIImage
    CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap);
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef];

    // Clean up
    CGContextRelease(bitmap);
    CGImageRelease(newImageRef);

    return newImage;
}

저는 Evgenii Kanvets가 게시한 Swift 3가 이미지를 균일하게 축소하지 않는다는 것을 발견했습니다.

이미지를 축소하지 않는 기능의 Swift 4 버전은 다음과 같습니다.

static func resizedCroppedImage(image: UIImage, newSize:CGSize) -> UIImage? {

    // This function returns a newImage, based on image
    // - image is scaled uniformaly to fit into a rect of size newSize
    // - if the newSize rect is of a different aspect ratio from the source image
    //     the new image is cropped to be in the center of the source image
    //     (the excess source image is removed)

    var ratio: CGFloat = 0
    var delta: CGFloat = 0
    var drawRect = CGRect()

    if newSize.width > newSize.height {

        ratio = newSize.width / image.size.width
        delta = (ratio * image.size.height) - newSize.height
        drawRect = CGRect(x: 0, y: -delta / 2, width: newSize.width, height: newSize.height + delta)

    } else {

        ratio = newSize.height / image.size.height
        delta = (ratio * image.size.width) - newSize.width
        drawRect = CGRect(x: -delta / 2, y: 0, width: newSize.width + delta, height: newSize.height)

    }

    UIGraphicsBeginImageContextWithOptions(newSize, true, 0.0)
    image.draw(in: drawRect)
    let newImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    return newImage
} 

브래드 라슨의 코드를 수정했습니다.주어진 rect에서 이미지를 가로로 채웁니다.

-(UIImage*) scaleAndCropToSize:(CGSize)newSize;
{
    float ratio = self.size.width / self.size.height;

    UIGraphicsBeginImageContext(newSize);

    if (ratio > 1) {
        CGFloat newWidth = ratio * newSize.width;
        CGFloat newHeight = newSize.height;
        CGFloat leftMargin = (newWidth - newHeight) / 2;
        [self drawInRect:CGRectMake(-leftMargin, 0, newWidth, newHeight)];
    }
    else {
        CGFloat newWidth = newSize.width;
        CGFloat newHeight = newSize.height / ratio;
        CGFloat topMargin = (newHeight - newWidth) / 2;
        [self drawInRect:CGRectMake(0, -topMargin, newSize.width, newSize.height/ratio)];
    }

    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;
}
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0,0.0,ScreenWidth,ScreenHeigth)];
    [scrollView setBackgroundColor:[UIColor blackColor]];
    [scrollView setDelegate:self];
    [scrollView setShowsHorizontalScrollIndicator:NO];
    [scrollView setShowsVerticalScrollIndicator:NO];
    [scrollView setMaximumZoomScale:2.0];
    image=[image scaleToSize:CGSizeMake(ScreenWidth, ScreenHeigth)];
    imageView = [[UIImageView alloc] initWithImage:image];
    UIImageView* imageViewBk = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
    [self.view addSubview:imageViewBk];
    CGRect rect;
    rect.origin.x=0;
    rect.origin.y=0;
    rect.size.width = image.size.width;
    rect.size.height = image.size.height;

    [imageView setFrame:rect];

    [scrollView setContentSize:[imageView frame].size];
    [scrollView setMinimumZoomScale:[scrollView frame].size.width / [imageView frame].size.width];
    [scrollView setZoomScale:[scrollView minimumZoomScale]];
    [scrollView addSubview:imageView];

    [[self view] addSubview:scrollView];

그러면 당신은 이것으로 당신의 이미지에 스크린샷을 찍을 수 있습니다.

float zoomScale = 1.0 / [scrollView zoomScale];
CGRect rect;
rect.origin.x = [scrollView contentOffset].x * zoomScale;
rect.origin.y = [scrollView contentOffset].y * zoomScale;
rect.size.width = [scrollView bounds].size.width * zoomScale;
rect.size.height = [scrollView bounds].size.height * zoomScale;

CGImageRef cr = CGImageCreateWithImageInRect([[imageView image] CGImage], rect);

UIImage *cropped = [UIImage imageWithCGImage:cr];

CGImageRelease(cr);

사마린.UI 이미지 크기를 조정한 다음 자르기(Aspect Fill) 방법에 대한 답변이 허용된 iOS 버전은 아래와 같습니다.

    public static UIImage ScaleAndCropImage(UIImage sourceImage, SizeF targetSize)
    {
        var imageSize = sourceImage.Size;
        UIImage newImage = null;
        var width = imageSize.Width;
        var height = imageSize.Height;
        var targetWidth = targetSize.Width;
        var targetHeight = targetSize.Height;
        var scaleFactor = 0.0f;
        var scaledWidth = targetWidth;
        var scaledHeight = targetHeight;
        var thumbnailPoint = PointF.Empty;
        if (imageSize != targetSize)
        {
            var widthFactor = targetWidth / width;
            var heightFactor = targetHeight / height;
            if (widthFactor > heightFactor)
            {
                scaleFactor = widthFactor;// scale to fit height
            }
            else
            {
                scaleFactor = heightFactor;// scale to fit width
            }
            scaledWidth = width * scaleFactor;
            scaledHeight = height * scaleFactor;
            // center the image
            if (widthFactor > heightFactor)
            {
                thumbnailPoint.Y = (targetHeight - scaledHeight) * 0.5f;
            }
            else
            {
                if (widthFactor < heightFactor)
                {
                    thumbnailPoint.X = (targetWidth - scaledWidth) * 0.5f;
                }
            }
        }
        UIGraphics.BeginImageContextWithOptions(targetSize, false, 0.0f);
        var thumbnailRect = new RectangleF(thumbnailPoint, new SizeF(scaledWidth, scaledHeight));
        sourceImage.Draw(thumbnailRect);
        newImage = UIGraphics.GetImageFromCurrentImageContext();
        if (newImage == null)
        {
            Console.WriteLine("could not scale image");
        }
        //pop the context to get back to the default
        UIGraphics.EndImageContext();

        return newImage;
    }

저는 Sam Wirch의 가이드를 swift로 변환했고 그것은 저에게 잘 작동했습니다. 비록 최종 이미지에 제가 해결할 수 없는 아주 약간의 "꼬임"이 있습니다.

func resizedCroppedImage(image: UIImage, newSize:CGSize) -> UIImage {
    var ratio: CGFloat = 0
    var delta: CGFloat = 0
    var offset = CGPointZero
    if image.size.width > image.size.height {
        ratio = newSize.width / image.size.width
        delta = (ratio * image.size.width) - (ratio * image.size.height)
        offset = CGPointMake(delta / 2, 0)
    } else {
        ratio = newSize.width / image.size.height
        delta = (ratio * image.size.height) - (ratio * image.size.width)
        offset = CGPointMake(0, delta / 2)
    }
    let clipRect = CGRectMake(-offset.x, -offset.y, (ratio * image.size.width) + delta, (ratio * image.size.height) + delta)
    UIGraphicsBeginImageContextWithOptions(newSize, true, 0.0)
    UIRectClip(clipRect)
    image.drawInRect(clipRect)
    let newImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return newImage
}

객관적인 c 버전을 원하는 사람이 있다면, 그것은 그의 웹사이트에 있습니다.

윌리엄 T가 올린 샘 위치의 스위프트 3 버전의 스위프트 가이드입니다.

extension UIImage {

    static func resizedCroppedImage(image: UIImage, newSize:CGSize) -> UIImage? {
        var ratio: CGFloat = 0
        var delta: CGFloat = 0
        var offset = CGPoint.zero

        if image.size.width > image.size.height {
            ratio = newSize.width / image.size.width
            delta = (ratio * image.size.width) - (ratio * image.size.height)
            offset = CGPoint(x: delta / 2, y: 0)
        } else {
            ratio = newSize.width / image.size.height
            delta = (ratio * image.size.height) - (ratio * image.size.width)
            offset = CGPoint(x: 0, y: delta / 2)
        }

        let clipRect = CGRect(x: -offset.x, y: -offset.y, width: (ratio * image.size.width) + delta, height: (ratio * image.size.height) + delta)
        UIGraphicsBeginImageContextWithOptions(newSize, true, 0.0)
        UIRectClip(clipRect)
        image.draw(in: clipRect)
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        return newImage
    }

}

다음과 같은 간단한 코드가 저에게 효과가 있었습니다.

[imageView setContentMode:UIViewContentModeScaleAspectFill];
[imageView setClipsToBounds:YES];
- (UIImage*)imageScale:(CGFloat)scaleFactor cropForSize:(CGSize)targetSize
{
    targetSize = !targetSize.width?self.size:targetSize;
    UIGraphicsBeginImageContext(targetSize); // this will crop

    CGRect thumbnailRect = CGRectZero;

    thumbnailRect.size.width  = targetSize.width*scaleFactor;
    thumbnailRect.size.height = targetSize.height*scaleFactor;
    CGFloat xOffset = (targetSize.width- thumbnailRect.size.width)/2;
    CGFloat yOffset = (targetSize.height- thumbnailRect.size.height)/2;
    thumbnailRect.origin = CGPointMake(xOffset,yOffset);

    [self drawInRect:thumbnailRect];

    UIImage *newImage  = UIGraphicsGetImageFromCurrentImageContext();

    if(newImage == nil)
    {
        NSLog(@"could not scale image");
    }

    UIGraphicsEndImageContext();

    return newImage;
}

작업 예제 아래: 왼쪽 이미지 - (원점 이미지); 오른쪽 이미지(스케일 x2)

enter image description here

이미지의 크기를 조정하지만 프레임(비율)을 유지하려면 메소드를 다음과 같이 호출합니다.

[yourImage imageScale:2.0f cropForSize:CGSizeZero];

이 문제는 해결된 것 같습니다. 하지만 좀 더 쉽게 이해할 수 있는 솔루션(Swift로 작성)을 모색하던 중 이 문제에 도달했습니다(UI 이미지를 자르는 방법도 게시됨).


저는 가로 세로 비율을 기준으로 한 지역에서 자를 수 있고, 바깥쪽 경계 범위를 기준으로 한 크기로 확장할 수 있기를 원했습니다.다음은 나의 변형입니다.

import AVFoundation
import ImageIO

class Image {

    class func crop(image:UIImage, crop source:CGRect, aspect:CGSize, outputExtent:CGSize) -> UIImage {

        let sourceRect = AVMakeRectWithAspectRatioInsideRect(aspect, source)
        let targetRect = AVMakeRectWithAspectRatioInsideRect(aspect, CGRect(origin: CGPointZero, size: outputExtent))

        let opaque = true, deviceScale:CGFloat = 0.0 // use scale of device's main screen
        UIGraphicsBeginImageContextWithOptions(targetRect.size, opaque, deviceScale)

        let scale = max(
            targetRect.size.width / sourceRect.size.width,
            targetRect.size.height / sourceRect.size.height)

        let drawRect = CGRect(origin: -sourceRect.origin * scale, size: image.size * scale)
        image.drawInRect(drawRect)

        let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        return scaledImage
    }
}

제가 혼란스럽게 생각한 것이 몇 가지 있는데, 자르기와 크기 조정에 대한 별개의 문제입니다.자르기는 사용자가 drawInRect로 전달하는 정류의 원점으로 처리되며 스케일링은 크기 부분으로 처리됩니다.제 경우에는 소스에 있는 자르기 직선의 크기를 동일한 가로 세로 비율의 출력 직선과 관련지어야 했습니다.그런 다음 스케일 팩터가 출력/입력되고 이를 drawRect(drawInRect로 전달)에 적용해야 합니다.

한 가지 주의할 점은 이 접근 방식은 그리는 이미지가 이미지 컨텍스트보다 크다고 효과적으로 가정한다는 것입니다.테스트하지 않았지만 이 코드를 사용하여 자르기/확대를 처리할 수 있지만 위에서 언급한 스케일 매개 변수로 스케일 매개 변수를 명시적으로 정의할 수 있습니다.기본적으로 UIKit은 화면 해상도에 따라 승수를 적용합니다.

마지막으로, 이 UIKit 접근 방식은 CoreGraphics/Quartz 및 CoreImage 접근 방식보다 높은 수준이며 이미지 방향 문제를 처리하는 것으로 보입니다.또한 Image에 이어 매우 빠르다는 점도 언급할 가치가 있습니다.다음 게시물에 따르면 IO: http://nshipster.com/image-resizing/

빠른 버전:

    static func imageWithImage(image:UIImage, newSize:CGSize) ->UIImage {
    UIGraphicsBeginImageContextWithOptions(newSize, true, UIScreen.mainScreen().scale);
    image.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))

    let newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
    return newImage
}

@Chris Capener의 Swift 버전에는 작은 버그가 있습니다.원본 이미지와 크기가 조정된 이미지가 모두 가로이며 원본 이미지가 크기가 조정된 이미지보다 가로 세로 비율이 높은 경우(또는 가로 세로 비율이 낮은 원래 이미지 모두) 잘못된 코드 경로가 사용됩니다.

확인하는 대신if newSize.width > newSize.height확인이 필요합니다.if aspectRatio < newAspectRatio저는 이를 변경하고 UI 이미지의 확장으로 코드를 이동했습니다.저는 또한 iOS 10+용 최신 UIGraphics Image Renderer를 사용하는 것으로 전환했습니다.

extension UIImage {
    // This function returns a newImage, based on image
    // - image is scaled uniformly to fit into a rect of size newSize
    // - if the newSize rect is of a different aspect ratio from the source
    //   image the new image is cropped to be in the center of the source image
    //   (the excess source image is removed)
    func resizedAndCroppedTo(_ newSize: CGSize) -> UIImage? {

        let aspectRatio = size.width / size.height
        let newAspectRatio = newSize.width / newSize.height

        var drawRect = CGRect()

        if aspectRatio < newAspectRatio {
            // width-limited
            let ratio = newSize.width / size.width
            let delta = (ratio * size.height) - newSize.height
            drawRect = CGRect(x: 0, y: -delta / 2, width: newSize.width, height: newSize.height + delta)
            
        } else {
            // height-limited
            let ratio = newSize.height / size.height
            let delta = (ratio * size.width) - newSize.width
            drawRect = CGRect(x: -delta / 2, y: 0, width: newSize.width + delta, height: newSize.height)
        }
        
        return UIGraphicsImageRenderer(size: newSize).image { _ in
            draw(in: drawRect)
        }
    }
}

변경 전과 변경 후의 결과는 다음과 같습니다.상단은 가로 세로 비율이 3.33인 원본 이미지입니다.중간 이미지의 크기가 원래 코드를 사용하여 조정되었습니다.가로 세로 비율은 1.67입니다.보시는 것처럼 전체 이미지를 유지하고 위와 아래에 검은색 막대를 남깁니다.하단 이미지의 크기가 수정된 코드를 사용하여 조정되었습니다.전체 뷰를 정확하게 채우고 측면을 잘라냅니다.

example with original and modified code

언급URL : https://stackoverflow.com/questions/603907/uiimage-resize-then-crop