类说明
CAImage贴图类,即内存中的纹理,主要用于创建贴图对象,将图像加载进内存,是所有有关贴图类的基础。
CAImage 属性(点击方法名可查看方法介绍)
| 属性 | 说明 | 
| PixelFormat | 像素格式 | 
| PixelsWide | 像素宽 | 
| PixelsHigh | 像素高 | 
| ContentSize | 内容大小 | 
| ShaderProgram | 着色程序 | 
| Monochrome | 单色 | 
| Data | 数据 | 
| DataLenght | 数据长度 | 
CAImage 方法(点击方法名可查看方法介绍)
| 方法 | 说明 | 
| create | 创建,默认Frame为(0,0,0,0) | 
| createWithImageDataNoCache | 创建,默认没有缓存 | 
| createWithImageData | 创建,默认有缓存 | 
| createWithString | 创建,并指定文本内容 | 
| getFontHeight | 获得字体高度 | 
| getStringWidth | 获得字体宽度 | 
| cutStringByWidth | 减少字符串的宽度 | 
| getStringHeight | 减少字符串的高度 | 
| scaleToNewImageWithImage | 缩放当前图像做新图像 | 
| scaleToNewImageWithImage | 缩放当前图像做新图像 | 
| generateMipmapsWithImage | 生成mipmap图像 | 
| createWithRawDataNoCache | 创建,并指定Raw Data,默认没有缓存 | 
| createWithRawData | 创建,并指定Raw Data,默认没有缓存 | 
| initWithImageFile | 初始化,并指定其图像文件 | 
| initWithImageFileThreadSafe | 初始化,并指定其图像文件(支持子线程) | 
| initWithImageData | 初始化,并指定其图像缓存 | 
| initWithRawData | 初始化,并指定其原数据 | 
| description | 添加图像描述 | 
| releaseData | 释放所有数据 | 
| releaseData | 释放指定数据 | 
| drawAtPoint | 基于某个点显示(大小为图像大小) | 
| drawInRect | 基于某个矩形区域显示 | 
| initWithETCFile | 初始化,并指定其ETC文件 | 
| stringForFormat | 格式字符串 | 
| saveToFile | 保存到文件 | 
| getImageFileType | 获取图像文件类型 | 
| getAspectRatio | 得到长宽比 | 
| detectFormat | 检测格式 | 
| premultipliedImageData | 进行图像数据 | 
| repremultipliedImageData | 再进行图像数据 | 
| updateGifImageWithIndex | 通过index更新GIF图像 | 
| getGifImageIndex | 获取GIF图像的index | 
| getGifImageCounts | 获取GIF图像的参数 | 
| reloadAllImages | 重新加载所有图像 | 
CAImageView 属性(点击方法名可查看方法介绍)
| 属性 | 说明 | 
| ImageViewScaleType | 图像缩放类型 | 
| AnimationImages | 动画图像 | 
| AnimationDuration | 动画间隔的时间 | 
| AnimationRepeatCount | 动画重复次数 | 
CAImageView 方法(点击方法名可查看方法介绍)
| 方法 | 说明 | 
| create | 创建,默认Frame为(0,0,0,0) | 
| createWithImage | 创建,并指定Image | 
| createWithFrame | 创建,并指定Frame,默认Frame为(0,0,0,0) | 
| createWithCenter | 创建,并指定Center,默认Center为(0,0,0,0) | 
| init | 初始化 | 
| initWithImage | 初始化,并指定其图像 | 
| setImage | 设置图像 | 
| getImage | 获取图像 | 
| setImageAsyncWithFile | 异步设置图像文件 | 
| startAnimating | 开始动画 | 
| stopAnimating | 结束动画 | 
| isAnimating | 查看图像动画 | 
使用方法
//创建一个CAImage
    CAImage* image = CAImage::create("HelloWorld.png");
 
//CAImage函数
//打印贴图描述
    CCLog("Description:%s", image->description());
 
//打印像素格式
    CCLog("StringForFormat:%s", image->stringForFormat());
     
//打印像素位深
    CCLog("bitsPerPixelForFormat:%d", image->bitsPerPixelForFormat());
     
//方法一:通过CAImage创建一个CAImageView
    CAImageView* imageView = CAImageView::createWithImage(image);
     
//设置显示的范围(如果不设置,默认不会被显示出来)
    imageView->setFrame(winRect);
     
//添加到绘制
     this->getView()->addSubview(imageView);
      
//方法二:通过设置Center创建一个CAImageViewD
     CAImageView* imageView_1 = CAImageView::createWithCenter(DRect(50,50,100,100));
      
//设置显示的纹理
     imageView_1->setImage(image);
      
//异步加载
     //imageView_1->setImageAsyncWithFile("source_material/stepper_inc_n.png");
      
//添加到绘制,设置z轴为1
     this->getView()->insertSubview(imageView_1,1);
        CCLog的打印结果:
    Description:<CAImage | Name = 3 | Dimensions = 640 x 960 | Coordinates = (1.00, 1.00)>    StringForFormat:RGB888    bitsPerPixelForFormat:32CAImage 属性说明
类型:CAImage::PixelFormat
解释:像素格式。get{}。
类型:unsigned int
解释:像素宽。get{}。
类型:unsigned int
解释:像素高。get{}。
类型:DSize
解释:内容大小。get{}。
类型:CAGLProgram*
解释:着色程序。set/get{}。
类型:bool
解释:单色。is{}。
类型:unsigned char*
解释:数据。get{}。
类型:unsigned long
解释:数据长度。get{}。
CAImage 方法说明
static CAImage* create(const std::string& file);
返回值:static CAImage*
参数:
| 类型 | 参数名 | 说明 | 
| const std::string& | file | 图像名 | 
解释:创建,默认Frame为(0,0,0,0)
static CAImage* createWithImageDataNoCache(const unsigned char * data, unsigned long lenght);
返回值:static CAImage*
参数:
| 类型 | 参数名 | 说明 | 
| const unsigned char * | data | 数据 | 
| unsigned long | lenght | 长度 | 
解释:创建,默认没有缓存
static CAImage* createWithImageData(const unsigned char * data, unsigned long lenght, const std::string& key);
返回值:static CAImage*
参数:
| 类型 | 参数名 | 说明 | 
| const unsigned char * | data | 数据 | 
| unsigned long | lenght | 长度 | 
| const std::string& | key | 属性 | 
解释:创建,默认有缓存
static CAImage* createWithString(const char *text, const char *fontName, float fontSize, const DSize& dimensions, CATextAlignment hAlignment, CAVerticalTextAlignment vAlignment, bool isForTextField = false, int iLineSpacing = 0, bool bBold = false, bool bItalics = false, bool bUnderLine = false);
返回值:static CAImage*
参数:
| 类型 | 参数名 | 说明 | 
| const char | *text | 文字 | 
| const char | *fontName | 字体名称 | 
| float | fontSize | 字体大小 | 
| const DSize& | dimensions | 图像大小 | 
| CATextAlignment | hAlignment | 文本对齐 | 
| CAVerticalTextAlignment | vAlignment | 垂直文本对齐 | 
| bool | isForTextField = false | 是否显示文本框(默认不显示) | 
| int | iLineSpacing = 0 | 文本间距(默认0) | 
| bool | bBold = false | 是否显示加粗(默认不加粗) | 
| bool | bItalics = false | 是否显示斜体(默认不斜体) | 
| bool | bUnderLine = false | 是否显示下划线(默认不显示) | 
解释:创建,并指定文本内容
static int getFontHeight(const char* pFontName, unsigned long nSize);
返回值:static int
参数:
| 类型 | 参数名 | 说明 | 
| const char* | pFontName | 字体名字 | 
| unsigned long | nSize | 字体大小 | 
解释:获得字体高度
static int getStringWidth(const char* pFontName, unsigned long nSize, const std::string& pText);
返回值:static int
参数:
| 类型 | 参数名 | 说明 | 
| const char* | pFontName | 字体名字 | 
| unsigned long | nSize | 字体大小 | 
| const std::string& | pText | 文本内容 | 
解释:获得字体宽度
static int cutStringByWidth(const char* pFontName, unsigned long nSize, const std::string& text, int iLimitWidth, int& cutWidth);
返回值:static int
参数:
| 类型 | 参数名 | 说明 | 
| const char* | pFontName | 字体名字 | 
| unsigned long | nSize | 字体大小 | 
| const std::string& | pText | 文本内容 | 
| int | iLimitWidth | 最大宽度 | 
| int& | cutWidth | 减少的宽度 | 
解释:减少字符串的宽度
static int getStringHeight(const char* pFontName, unsigned long nSize, const std::string& pText, int iLimitWidth, int iLineSpace = 0, bool bWordWrap = true);
返回值:static int
参数:
| 类型 | 参数名 | 说明 | 
| const char* | pFontName | 字体名字 | 
| unsigned long | nSize | 字体大小 | 
| const std::string& | pText | 文本内容 | 
| int | iLimitWidth | 最大宽度 | 
| int | iLineSpace = 0 | 间距 | 
| bool | bWordWrap = true | 自动换行 | 
解释:减少字符串的高度
static CAImage* scaleToNewImageWithImage(CAImage* image, const DSize& size);
返回值:static CAImage*
参数:
| 类型 | 参数名 | 说明 | 
| CAImage* | image | 图像 | 
| const DSize& | size | 大小 | 
解释:缩放当前图像做新图像
static CAImage* scaleToNewImageWithImage(CAImage* image, float scaleX, float scaleY);
返回值:static CAImage*
参数:
| 类型 | 参数名 | 说明 | 
| CAImage* | image | 图像 | 
| float | scaleX | 缩放X轴 | 
| float | scaleY | 缩放Y轴 | 
解释:缩放当前图像做新图像
static CAImage* generateMipmapsWithImage(CAImage* image);
返回值:static CAImage*
参数:
| 类型 | 参数名 | 说明 | 
| CAImage* | image | 图像 | 
解释:生成mipmap图像
static CAImage* createWithRawDataNoCache(const unsigned char * data, const CAImage::PixelFormat& pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh);
返回值:static CAImage*
参数:
| 类型 | 参数名 | 说明 | 
| const unsigned char * | data | 数据 | 
| const CAImage::PixelFormat& | pixelFormat | 像素格式 | 
| unsigned int | pixelsWide | 像素宽 | 
| unsigned int | pixelsHigh | 像素高 | 
解释:创建,并指定Raw Data,默认没有缓存
static CAImage* createWithRawData(const unsigned char * data, const CAImage::PixelFormat& pixelFormat, nsigned int pixelsWide, unsigned int pixelsHigh, const std::string& key);
返回值:static CAImage*
参数:
| 类型 | 参数名 | 说明 | 
| const unsigned char * | data | 数据 | 
| const CAImage::PixelFormat& | pixelFormat | 像素格式 | 
| unsigned int | pixelsWide | 像素宽 | 
| unsigned int | pixelsHigh | 像素高 | 
| const std::string& | key | 属性 | 
解释:创建,并指定Raw Data,默认有缓存
bool initWithImageFile(const std::string& file);
返回值:bool
参数:
| 类型 | 参数名 | 说明 | 
| const std::string& | file | 图像名 | 
解释:初始化,并指定其图像文件
bool initWithImageFileThreadSafe(const std::string& fullPath);
返回值:bool
参数:
| 类型 | 参数名 | 说明 | 
| const std::string& | fullPath | 完整路径 | 
解释:初始化,并指定其图像文件(支持子线程)
bool initWithImageData(const unsigned char * data, unsigned long dataLen);
返回值:bool
参数:
| 类型 | 参数名 | 说明 | 
| const unsigned char * | data | 数据 | 
| unsigned long | dataLen | 数据长度 | 
解释:初始化,并指定其图像缓存
bool initWithRawData(const unsigned char * data, const CAImage::PixelFormat& pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh);
返回值:bool
参数:
| 类型 | 参数名 | 说明 | 
| const unsigned char * | data | 数据 | 
| const CAImage::PixelFormat& | pixelFormat | 像素格式 | 
| unsigned int | pixelsWide | 像素宽 | 
| unsigned int | pixelsHigh | 像素高 | 
解释:初始化,并指定其原数据
const char* description(void);
返回值:const char*
参数:
解释:获取图像描述
返回值:void
参数:
解释:释放所有数据
void releaseData(unsigned char ** data);
返回值:void
参数:
| 类型 | 参数名 | 说明 | 
| unsigned char ** | data | 数据 | 
解释:释放指定数据
void drawAtPoint(const DPoint& point);
返回值:void
参数:
| 类型 | 参数名 | 说明 | 
| const DPoint& | point | 点的位置 | 
解释:基于某个点显示(大小为图像大小)
void drawInRect(const DPoint& rect);
返回值:void
参数:
| 类型 | 参数名 | 说明 | 
| const DPoint& | rect | 矩形大小 | 
解释:基于某个矩形区域显示
bool initWithETCFile(const char* file);
返回值:bool
参数:
| 类型 | 参数名 | 说明 | 
| const char* | file | 文件名 | 
解释:初始化,并指定其ETC文件
const char* stringForFormat();
返回值:const char*
参数:
解释:格式字符串
bool saveToFile(const std::string& fullPath, bool bIsToRGB = false);
返回值:bool
参数:
| 类型 | 参数名 | 说明 | 
| const std::string& | fullPath | 完全路径 | 
| bool | bIsToRGB = false | 是否用RGB格式保存(默认否) | 
解释:是否保存成RGB格式
const char* getImageFileType();
返回值:const char*
参数:
解释:获取图像文件类型
返回值:float
参数:
解释:得到长宽比
CAImage::Format detectFormat(const unsigned char * data, unsigned long dataLen);
返回值: CAImage::Format
参数:
| 类型 | 参数名 | 说明 | 
| const unsigned char * | data | 数据 | 
| unsigned long | dataLen | 数据长度 | 
解释:检测格式
void premultipliedImageData();
返回值:void
参数:
解释:进行图像数据
void repremultipliedImageData();
返回值:void
参数:
解释:再进行图像数据
void updateGifImageWithIndex(unsigned int index);
返回值:void
参数:
| 类型 | 参数名 | 说明 | 
| unsigned int | index | index | 
解释:通过index更新GIF图像
unsigned int getGifImageIndex();
返回值:unsigned int
参数:
解释:获取GIF图像的index
unsigned int getGifImageCounts();
返回值:unsigned int
参数:
解释:获取GIF图像的参数
static void reloadAllImages();
返回值:static void
参数:
解释:重新加载所有图像
CAImageView 属性说明
类型:CAImageViewScaleType
解释:图像缩放类型。set/get{}。
类型:CAVector<CAImage*>
解释:动画图像。set/get{}。
类型:float
解释:动画间隔的时间。set/get{}。
类型:unsigned int
解释:动画重复次数。set/get{}。
CAImageView 方法说明
返回值:static CAImageView*
参数:
解释:创建,默认Frame为(0,0,0,0)
static CAImageView* createWithImage(CAImage* image);
返回值:static CAImageView*
参数:
| 类型 | 参数名 | 说明 | 
| CAImage* | image | 图像 | 
解释:创建,并指定其Image
static CAImageView* createWithFrame(const DRect& rect);
返回值:static CAImageView*
参数:
| 类型 | 参数名 | 说明 | 
| const DRect& | rect | 区域大小 | 
解释:创建,并指定其Frame,默认Frame为(0,0,0,0)
static CAImageView* createWithCenter(const DRect& rect);
返回值:static CAImageView*
参数:
| 类型 | 参数名 | 说明 | 
| const DRect& | rect | 中心点的位置及大小 | 
解释:创建,并指定其Center,默认Center为(0,0,0,0)
返回值:virtual bool
参数:
解释:初始化
virtual bool initWithImage(CAImage* image);
返回值:virtual bool
参数:
| 类型 | 参数名 | 说明 | 
| CAImage* | image | 图像 | 
解释:初始化图像
virtual void setImage(CAImage* image);
返回值:virtual void
参数:
| 类型 | 参数名 | 说明 | 
| CAImage* | image | 图像 | 
解释:设置图像
virtual CAImage* getImage(void);
返回值:virtual CAImage*
参数:
解释:获取图像
virtual void setImageAsyncWithFile(const std::string& path);
返回值:virtual void
参数:
| 类型 | 参数名 | 说明 | 
| const std::string& | path | 路径 | 
解释:异步设置图像文件
返回值:void
参数:
解释:开始动画
返回值:void
参数:
解释:结束动画
返回值:bool
参数:
解释:查看图像动画