当前位置:K88软件开发文章中心编程语言APP编程CrossApp → 文章内容

CAImage、CAImageView(显示一张图片)

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-23 13:51:41

由 ?﹏???ζ???﹏﹏? 创建, 最后一次修改 2016-08-27 类说明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图像的indexgetGifImageCounts获取GIF图像的参数reloadAllImages重新加载所有图像CAImageView 属性(点击方法名可查看方法介绍)属性说明ImageViewScaleType图像缩放类型AnimationImages动画图像AnimationDuration动画间隔的时间AnimationRepeatCount动画重复次数CAImageView 方法(点击方法名可查看方法介绍)方法说明create创建,默认Frame为(0,0,0,0)createWithImage创建,并指定ImagecreateWithFrame创建,并指定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 属性说明PixelFormat类型:CAImage::PixelFormat解释:像素格式。get{}。PixelsWide类型:unsigned int解释:像素宽。get{}。PixelsHigh类型:unsigned int解释:像素高。get{}。ContentSize类型:DSize解释:内容大小。get{}。ShaderProgram类型:CAGLProgram*解释:着色程序。set/get{}。Monochrome类型:bool解释:单色。is{}。Data类型:unsigned char*解释:数据。get{}。DataLenght类型: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 longlenght长度解释:创建,默认没有缓存static CAImage* createWithImageData(const unsigned char * data, unsigned long lenght, const std::string& key);返回值:static CAImage*参数:类型参数名说明const unsigned char *data数据unsigned longlenght长度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字体名称floatfontSize字体大小const DSize&dimensions图像大小CATextAlignmenthAlignment文本对齐CAVerticalTextAlignmentvAlignment垂直文本对齐boolisForTextField = false是否显示文本框(默认不显示)intiLineSpacing = 0文本间距(默认0)boolbBold = false是否显示加粗(默认不加粗)boolbItalics = false是否显示斜体(默认不斜体)boolbUnderLine = false是否显示下划线(默认不显示)

[1] [2] [3]  下一页


CAImage、CAImageView(显示一张图片)