IOS图片自适应后绘制在scrollview上

本文深入探讨了OpenGL ES滤镜、OpenCV图像处理、人脸标定AR、人像分割抠像等图像处理与AR特效技术,为读者提供了一套完整的图像处理与AR特效解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#import <UIKit/UIKit.h>

@interface UIImage (QDImage)


/**

 根据传key(图片名字)从工程路径或自定义路径中获取到一张图片

 @param key 需要获取的图片名字

 @return 返回图片名对应的图片

 */

+(UIImage *)QDResourcesImagePathString:(NSString *)key;


+(UIImage *)fitSmallImage:(UIImage *)image;

@end




//

//  UIImage+QDImage.m

//  QDmShow

//

//  Created by huxiaohui on 7/23/13.

//  Copyright (c) 2013 huxiaohui. All rights reserved.

//


#import "UIImage+QDImage.h"

#define IMAGE_MAX_SIZE_WIDTH 212

#define IMAGE_MAX_SIZE_GEIGHT 290

#define QDImageResourcesPathString(key) [DOCUMENTS_PATH stringByAppendingPathComponent:[NSString stringWithFormat:@"QDResources/Image/%@",key]]


@implementation UIImage (QDImage)


+(UIImage *)QDResourcesImagePathString:(NSString *)key

{

//    UIImage *image = [UIImage imageWithContentsOfFile:QDImageResourcesPathString(key)];

    UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForAuxiliaryExecutable:key]];

    

    return image;

}


+(UIImage *)fitSmallImage:(UIImage *)image

{

    if (nil == image)

    {

        return nil;

    }

    if (image.size.width<IMAGE_MAX_SIZE_WIDTH && image.size.height<IMAGE_MAX_SIZE_GEIGHT)

    {

        return image;

    }

    CGSize size = [self fitsize:image.size];

    UIGraphicsBeginImageContext(size);

    CGRect rect = CGRectMake(0, 0, size.width, size.height);

    [image drawInRect:rect];

    UIImage *newing = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newing;

}



+ (CGSize)fitsize:(CGSize)thisSize

{

    if(thisSize.width == 0 && thisSize.height ==0)

        return CGSizeMake(0, 0);

    CGFloat wscale = thisSize.width/IMAGE_MAX_SIZE_WIDTH;

    CGFloat hscale = thisSize.height/IMAGE_MAX_SIZE_GEIGHT;

    CGFloat scale = (wscale>hscale)?wscale:hscale;

    CGSize newSize = CGSizeMake(thisSize.width/scale, thisSize.height/scale);

    return newSize;

}



@end



----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void)setQuaDic:(NSDictionary *)quaDic

{

    _quaDic = quaDic;


    int contentCount = [[_quaDic objectForKey:@"contentCount"] intValue];

    int imgCount = [[_quaDic objectForKey:@"imgCount"] intValue];

    

    int swsCount = contentCount>imgCount?contentCount:imgCount;

    

    float frameY = 14;

    

    for (int i = 0; i< swsCount; i++)

    {

        if (i < contentCount)

        {

            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, frameY, 320, 30)];

            [label setFont:[UIFont boldSystemFontOfSize:17]];

            [label setBackgroundColor:[UIColor clearColor]];

            [label setTextAlignment:NSTextAlignmentCenter];

            [quaScrollView addSubview:label];

            [label setText:[[[_quaDic objectForKey:@"contents"] objectAtIndex:i] objectForKey:@"content"]];

            frameY +=label.frame.size.height;

        }

        if (i < imgCount)

        {

            UIImageView *certificateImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, frameY, 212, 290)];

            QDNetworkMaster *networkMaster = [[QDNetworkMaster alloc] init];

            UIImage *imageData = [UIImage fitSmallImage:[networkMaster getImageDataByFileKey:[[[_quaDic objectForKey:@"imgs"] objectAtIndex:i] objectForKey:@"img"]]];

            [certificateImageView setFrame:CGRectMake((320-imageData.size.width)/2, frameY, imageData.size.width, imageData.size.height)];

            [certificateImageView setImage:imageData];

            [quaScrollView addSubview:certificateImageView];

            frameY +=certificateImageView.frame.size.height;

            

        }

        frameY += 10;

    }

    [quaScrollView setContentSize:CGSizeMake(320, frameY)];

}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值