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 有什么区别?


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01