cocos2dx之CCImage
来源:互联网 发布:白日梦想家知乎 编辑:程序博客网 时间:2024/06/06 01:49
CCImage在"CCImage.h"中定义,表示一张加载到内存的纹理图片。在其内部的实现中,纹理以每个像素的颜色值保存在内存之中。CCImage通常作为文件和显卡间数据交换的一个工具,因此主要提供了两个方面的功能:一方面是文件的加载与保存,另一方面是内存缓冲区的读写。
我们可以使用CCImage轻松地读写图片文件。目前,CCImage支持PNG、JPEG和TIFF三种主流的图片格式。下面列举与文件读写相关的方法:
/** @brief Load the image from the specified path. @param strPath the absolute file path @param imageType the type of image, now only support tow types. @return true if load correctly */ bool initWithImageFile(const char * strPath, EImageFormat imageType = kFmtPng); /* @brief The same meaning as initWithImageFile, but it is thread safe. It is casued by loadImage() in CCTextureCache.cpp. @param fullpath full path of the file @param imageType the type of image, now only support tow types. @return true if load correctly */ bool initWithImageFileThreadSafe(const char *fullpath, EImageFormat imageType = kFmtPng);
/** @brief Save the CCImage data to specified file with specified format. @param pszFilePath the file's absolute path, including file subfix @param bIsToRGB if the image is saved as RGB format */ bool saveToFile(const char *pszFilePath, bool bIsToRGB = true);
CCImage也提供了读写内存的接口。getData和getDataLen这两个方法提供了获取当前纹理的缓冲区的功能,而initWithImageData方法提供了使用像素数据初始化图片的功能。相关的方法定义如下:
unsigned char * getData() { return m_pData; } int getDataLen() { return m_nWidth * m_nHeight; }
/** @brief Load image from stream buffer. @warning kFmtRawData only support RGBA8888 @param pBuffer stream buffer that hold the image data @param nLength the length of data(managed in byte) @param nWidth, nHeight, nBitsPerComponent are used for kFmtRawData @return true if load correctly */ bool initWithImageData(void * pData, int nDataLen, EImageFormat eFmt = kFmtUnKnown, int nWidth = 0, int nHeight = 0, int nBitsPerComponent = 8);
0 0
- cocos2dx教程之CCImage
- cocos2dx之CCImage
- Cocos2d-x之CCImage深入分析
- Cocos2d-x之CCImage深入分析
- Cocos2d-x之CCImage深入分析
- Cocos2d-x之CCImage深入分析
- Cocos2d-x之CCImage深入分析
- Cocos2d-x之CCImage深入分析
- Cocos2d-x之CCImage深入分析
- Cocos2d-x之CCImage深入分析
- Cocos2d-x之CCImage深入分析
- Convert CCImage To UIImage
- CCImage(读取加载图片)
- Cocos2dx---之粒子系统
- Cocos2dx 之 ButtonSprite
- cocos2dx之curl下载
- cocos2dx之触摸事件
- 八、cocos2dx之TileMap
- 如何对待每逢佳节被逼婚
- jsp页面上四舍五入
- java比较两个日期大小
- 2014年目标
- 像素点和设备独立像素点的区别
- cocos2dx之CCImage
- wmi问题
- 新闻聚合阅读应用Facebook Paper的幕后功臣Origami
- Ubuntu中安装nfs服务器
- 简单字符串排序
- 安卓Activity的生命周期
- 动静态包含
- 临时改变终端语言
- 蓝牙基础知识进阶——Link Manager通用规则介绍