CGImageGetWidth(workingImage.CGImage)
和workingImage.size.width
之间有什么区别吗?第一个更快还是更安全?我知道在第二种情况下,我直接获得了价值。CGImageGetWidth(workingImage.CGImage)和workingImage.size.width是否有区别?
回答
其实他们都返回相同的结果。 CGImageGetWidth(Image.CGImage)
返回位图图像宽度,Image.size.width
返回UIImage宽度。如果你问安全/快速,我认为第一个会更快,因为它来自ApplicationServices框架,第二个是从UIKit框架。希望这有助于你..
你的意思是用C++实现一个,另一个用Objective-C实现? – trojanfoe
Apple在此(和大多数非Objective-C)情况下使用C,而不是C++。 –
不,它们并不总是返回相同的结果!我只是用http://stackoverflow.com/questions/1703100/resize-uiimage-with-aspect-ratio和http://stackoverflow.com/questions/2645768/uiimage-resize-scale中描述的方法调整了UIImage的大小 - 比例,并发现CGImageGetWidth(Image.CGImage)将返回原始图像的宽度,而不是调整后的宽度。 Image.size.width但是会返回缩放的宽度。 – Tafkadasoh
假设image
是UIImage *
,CGImageGetWidth(image.CGImage)
返回以像素为单位的宽度,而image.size.width
返回在屏幕坐标的宽度,即,像素宽度由image.scale
划分,这通常是比例因子的当前显示器(大多数Retina设备上有2个,iPhone 6 Plus上有3个),但它可以是任意值,具体取决于图像的创建方式。
在性能方面,我希望他们都〜相同的,因为它们都涉及到一个objc_msgSend()
:image.size
是一个方法调用来获取大小,image.CGImage
是一个方法调用来获取CGImageRef
。这些都是存储的属性,所以它们在任何情况下都不昂贵。
- 1. $ @和$ $是否有区别?
- 2. //和m //是否有区别?
- 3. 1.week和1.weeks是否有区别?
- 4. 在Perl中,/^/和/ ^/m是否有区别?
- 5. QString&和QString之间是否有区别?
- 6. .JPG和.jpg是否有区别?
- 7. ** copy **和** addAll **之间是否有区别?
- 8. $(e.currentTarget)和$(this)之间是否有区别?
- 9. UTF8Encoding.UTF8.GetBytes和Encoding.UTF8.GetBytes是否有区别?
- 10. `ListView.invalidateViews()`和'Adapter.notifyDataSetChanged()'之间是否有区别?
- 11. “margin:0 auto”是否有区别?和“margin:auto;”
- 12. `* x`和`x *`是否有区别?
- 13. Ruby中的“!=”和“!〜”是否有区别?
- 14. TINYINT(1)和INT(1)是否有区别?
- 15. Interop.AZROLESLib和Microsoft.Interop.Security.AzRoles是否有区别?
- 16. Web API和MVC HttpConfiguration是否有区别?
- 17. DB_DOUBLE和dbDouble是否有区别?
- 18. if $ str =“”和if($ str)是否有区别?
- 19. '/'和''路线是否有区别?
- 20. Phongap config.xml和Cordova config.xml是否有区别?
- 21. WebRTC和Websockets。是否有区别
- 22. HttpContext.Current.Request和HttpContext.Request是否有区别?
- 23. RSpec中'expect'和'should'是否有区别?
- 24. MASM shellcode和NASM shellcode是否有区别
- 25. _function和function之间是否有区别?
- 26. variant()和variant之间是否有区别?
- 27. RenderPartial和RenderPage是否有区别?
- 28. replica和replica之间是否有区别
- 29. ui:fragment和s:fragment之间是否有区别?
- 30. SqlConnection.CreateCommand和新的SqlCommand是否有区别?
'workingImage.size.width'对于'CGImageRef'不透明类型是否合法? – trojanfoe
在这两种情况下都可以。 –
虽然如何? 'CGImageRef'是**不是**对象!某种桥接?如果是这样,就有区别。 – trojanfoe