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

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

问题描述

我想在表格单元格中显示如此多的图像。我知道两种显示图像的方法。



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

  CGRect RECT = CGRectMake(X,Y,宽度,高度); 
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];

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



提前致谢....

解决方案

使用 drawInRect:方法,CoreGraphics使用CPU将图像绘制到活动的 CGContext 中。假设你在 UIView drawRect:方法中,这会将图像绘制到视图的缓冲区中。 / p>

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


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

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"]];

Another method is,

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?

Thanks in advance....

解决方案

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 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天全站免登陆