以编程方式将图像600x600调整为100x100 [英] resize image 600x600 to 100x100 programmatically

查看:127
本文介绍了以编程方式将图像600x600调整为100x100的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的图像高度为600,宽度也是600现在我想以100x100的形式在UIImageView中以编程方式显示该图像。我尝试但是图像不像原始图像我添加图像的屏幕截图首先是100x100,第二个是200x200。第二个很好。但是第一个不像原始图像。知道我做什么请

i have image which height is 600 and width is also 600 now i want to display that image Programmatically in UIImageView with 100x100. i try but image is not like as original image i add screen shoot of image First is 100x100 and Second is 200x200. second is fine.But first one is not like as original image. any idea what i do Please

In.h

@interface ViewController : UIViewController
{
    IBOutlet UIImageView *imageView1;
    IBOutlet UIImageView *imageView2;
}
@end

In.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    imageView1.frame=CGRectMake(100, 50, 100, 100);
    imageView2.frame=CGRectMake(50, 200, 200, 200);
    imageView1.image = [UIImage imageNamed:@"Untitled-7.png"];
    imageView2.image = [UIImage imageNamed:@"Untitled-7.png"];
}

推荐答案

请尝试使用此

UIImage *originalImage = [UIImage imageNamed:@"5.png"];
        CGSize destinationSize = CGSizeMake(100, 100);
        UIGraphicsBeginImageContext(destinationSize);
        [originalImage drawInRect:CGRectMake(0,0,destinationSize.width,destinationSize.height)];
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        UIImageView *newImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
        newImageView.image = newImage;
        [self.view addSubview:newImageView];

这篇关于以编程方式将图像600x600调整为100x100的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆