what is the difference between UIImageView and drawInRect?(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 中.假设您在 UIView 的 drawRect: 方法中,这会将图像绘制到视图的缓冲区中.
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 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIImageView 和 drawInRect 有什么区别?
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
