NSImage的缓存
来源:互联网 发布:淘宝买发票 编辑:程序博客网 时间:2024/06/05 19:10
The NSImage
class incorporates an internal caching scheme aimed at improving your application’s drawing performance. This caching scheme is an important part of image management and is enabled by default for all image objects; however, you can change the caching options for a particular image using the setCacheMode:
method of NSImage
. Table 6-2 lists the available caching modes.
Mode
Description
NSImageCacheDefault
Use the default caching mode appropriate for the image representation. This is the default value. For more information, seeTable 6-3.
NSImageCacheAlways
Always caches a version of the image.
NSImageCacheBySize
Creates a cached version of the image if the size set for the image is smaller than the size of the actual image data.
NSImageCacheNever
Does not cache the image. The image data is rasterized every time it is drawn.
Table 6-3 lists the behavior of each image representation when its cache mode is set toNSImageCacheDefault
.
Image representation
Cache behavior
NSBitmapImageRep
Behaves as if the NSImageCacheBySize
setting were in effect. Creates a cached copy if the bitmap depth does not match the screen depth or if the bitmap resolution is greater than 72 dpi.
NSCachedImageRep
Not applicable. This class is used to implement caching.
NSCIImageRep
Behaves as if the NSImageCacheBySize
setting were in effect. Creates a cached copy if the bitmap depth does not match the screen depth or if the bitmap resolution is greater than 72 dpi.
NSPDFImageRep
Behaves as if the NSImageCacheAlways
setting were in effect.
NSEPSImageRep
Behaves as if the NSImageCacheAlways
setting were in effect.
NSCustomImageRep
Behaves as if the NSImageCacheAlways
setting were in effect.
NSPICTImageRep
Behaves as if the NSImageCacheBySize
setting were in effect. Creates a cached copy of the PICT image if it contains a bitmap whose depth does not match the screen depth or if that bitmap resolution is greater than 72 dpi.
Caching is a useful step toward preparing an image for display on the screen. When first loaded, the data for an image representation may not be in a format that can be rendered directly to the screen. For example, PDF data, when loaded into a PDF image representation, must be rasterized before it can be sent to the graphics card for display. With caching enabled, aNSPDFImageRep
object rasterizes the PDF data before drawing it to the screen. The image representation then saves the raster data to alleviate the need to recreate it later. If you disable caching for such images, the rasterization process occurs each time you render the image, which can lead to a considerable performance penalty.
For bitmap image representations, the decision to cache is dependent on the bitmap image data. If the bitmap’s color space, resolution, and bit depth match the corresponding attributes in the destination device, the bitmap may be used directly without any caching. If any of these attributes varies, however, the bitmap image representation may create a cached version instead.
Important: It is important to remember that caching is aimed at improving performance during screen updates. During printing, Cocoa uses the native image data and resolution whenever possible and uses cached versions of the image only as a last resort.
If you change the contents of an image representation object directly, you should invoke therecache
method of the owning NSImage
object when you are done and want the changes to be reflected on the screen. Cocoa does not automatically track the changes you make to your image representation objects. Instead, it continues to use the cached version of your image representation until you explicitly clear that cache using the recache
method.
Caching and Image Data Retention
Because caching can lead to multiple copies of theimage data in memory,NSImage
usually dismisses the original image data once a cached copy is created. Dismissing the original image data saves memory and improves performance and is appropriate in situations where you do not plan on changing theimage size or attributes. If you do plan on changing the image size or attributes, you may want to disable this behavior. Enabling data retention prevents image degradation by basing changes on the original image data, as opposed to the currently cached copy.
To retain image data for a specific image, you must send asetDataRetained:
message to the NSImage
object. Preferably, you should send this message immediately after creating the image object. If you send the message after rendering the image or locking focus on it, Cocoa may need to read the image data more than once.
- NSImage的缓存
- NSImage的坐标系统
- NSImage的作用
- NSImage
- 对NSImage的一个扩展
- NSimage的size和pixels
- 对NSImage的一个扩展
- nsimage 转 png ,jpg的nsdata 类型
- NSImage的Drawing方法与Compositing方法的对比
- 解决JPG文件和NSImage分辨率不同的问题
- NSImage 存储为jpg或png文件的方法
- 实现将NSImage保持指定像素的拉伸
- 【Mac OS X开发】实现NSImage对其指定像素的保持及拉伸
- [Cocoa]_[初级]_[NSString 、NSImage、NSData、std::string之间的转换]
- save NSImage instance
- NSImage和NSImageRep
- NSImage加载图片
- NSImage加载图片
- Windows网络编程经验小结
- 在Domino中使用LOG4J遇到java.security.AccessControlException的解决办法
- (*(volatile unsigned *)0x56000010)解释。
- kobject之kobject_uevent.c文件分析
- 使用grub4dos引导Linux
- NSImage的缓存
- new是怎么用的?
- 我为什么写博客
- 一起来做NES开发(2)-反汇编
- 实习的时候拿C++写的游戏《星际夺宝》
- web应用每晚12点定时执行程序代码实例
- 绝杀!!!(成都online2011)
- 简单工程Makefile模版 及资料
- Barn Repair修理牛棚