0
点赞
收藏
分享

微信扫一扫

ios开发中因图片被拉伸而影响性能怎么解决?

兽怪海北 2021-09-29 阅读 60

     开发中有时候可能会因为图片被拉伸,从而会影响程序的体验性能。这里给大家介绍一种检查图片是否被拉伸的方法和解决图片拉伸的方法。

     在ViewController中创建一个UIImageView给其添加上名字叫tupian.jpg的图片。然后在xcode上运行。。。

UIImageView *testImageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
[self.view addSubview:testImageView];
testImageView.image = [UIImage imageNamed:@"tupian.jpg"];

     方法一:使用xcode自带的模拟器来检测图片是否被拉伸。

     检测方法操作步骤:

==>(1)、运行xcode的在模拟器上将图片先显示出来,如下图:

==>(2)、使用鼠标点中模拟器然后进行下图操作,你会发现你的模拟器整个屏幕都变成黄色的,不用担心:

==>(3)、解决方法,在使用UIImageView显示图片的位置加上下边的代码黄色就会消失,拉伸问题解决。

- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *testImageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
[self.view addSubview:testImageView];
testImageView.image = [UIImage imageNamed:@"tupian.jpg"];
===============+++已下代码++==============
UIGraphicsBeginImageContextWithOptions(testImageView.bounds.size, YES, 0);
//绘制图像
[testImageView.image drawInRect:testImageView.bounds];
//取得结果
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
[testImageView setImage:result];
}

真机上检测操作步骤:

==>1.

==>2.

==>3.

以上步骤操作完成后能达到与模拟器相同的效果。

举报

相关推荐

0 条评论