UIImageView 和 drawInRect 有什么区别? [英] what is the difference between UIImageView and drawInRect?

查看:14
本文介绍了UIImageView 和 drawInRect 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表格单元格中显示这么多图像.我知道两种显示图像的方法.

I want to display so many images in table cells. I knew two methods to show an image.

一个正在为 UIImageView 创建一个实例并显示它

One is creating an instance to UIImageView and show it

CGRect rect=CGRectMake(x,y,width,height);
UIImageView *image=[[UIImageView alloc]initWithFrame:rect];
[image setImage:[UIImage imageNamed:@"sample.jpg"]];

另一种方法是,

CGRect rect=CGRectMake(x,y,width,height);
[[UIImage imageNamed:@"sample.jpg"] drawInRect:rect];

现在,我的问题是,这两者有什么区别?哪一个是高效的?还是有比这更好的功能?

Now, my question is, what is the difference between these two? Which one is efficient? Or someother function is available better than this?

提前谢谢....

推荐答案

使用 drawInRect: 方法让 CoreGraphics 使用 CPU 将图像绘制到活动的 CGContext 中.假设您在 UIViewdrawRect: 方法中,这会将图像绘制到视图的缓冲区中.

Using the drawInRect: method has CoreGraphics draw the image into the active CGContext using the CPU. Assuming you're in a UIView's drawRect: method, this will paint the image into the view's buffer.

UIImageView 使用分配给它的任何图像作为它的后备缓冲区,而不是使用较慢的 drawRect:.然后,当通过 QuartzCore 合成屏幕时,GPU 会直接引用此缓冲区.

UIImageView uses whichever image is assigned to it as it's backing buffer instead of using the slower drawRect:. The GPU then references this buffer directly when the screen is composited via QuartzCore.

这篇关于UIImageView 和 drawInRect 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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