crossApp初级-CAIamgeView-6

类的继承关系:

CAOject-CAImage-CAView-CAImageView

一。CAImage类

CAImage贴图类,即内存中的纹理,主要用于创建贴图对象,将图像加载进内存,是所有有关贴图类的基础。没有方法呈现到屏幕,要呈现出来需要用CAImageView类实现。


基类
    CAObject
方法
访问修饰符        方法名                        说明
public        create                                创建贴图
public        description                        贴图描述
public        releaseData                       释放数据
public        keepData                           保存数据
public        drawAtPoint                       在指定文职绘制贴图
public        drawInRect                         绘制贴图上的指定区域
public        stringForFormat                 像素格式
public        bitsPerPixelForFormat        像素位深
public        bitsPerPixelForFormat        指定格式像素位深
public        getContentSizeInPixels       获取像素大小


二。CAImageView类

类说明

图片控件,将图像显示到屏幕上。

基类

CAView

属性

访问修饰符

属性名

说明

public

Image

imageView所显示的图像

protected

ImageViewScaleType

imageView的缩放模式

方法

访问修饰符

方法名

说明

public

createWithImage

使用CAImage加载贴图创建imageView

public

setImageAsyncWithFile

采用异步的方式加载贴图

属性介绍

Image

类型:CAImage*

解释:imageView的图像属性,即显示出来的内容,public get/set{}

 

ImageViewScaleType

类型:CAImageViewScaleType

解释:设置imageView的缩放模式,包括五种模式:默认fitImageXY,完全填充;fitImageCrop,在不变形的情况下,完全填充,对于超出的部分自动进行裁剪;fitImageInside,完全填充,不变形; fitViewByHorizontal,保持不变形的情况下,完全显示,横向适应图片;fitViewByVertical,保持不变形的情况下,完全显示,纵向适应图片。public get/set{}

方法介绍

static CAImageView* createWithImage(CAImage* image)

返回值:static CAImageView*

参数:

类型

参数名

说明

CAImage*

image

使用的贴图对象

   解释:创建一个imageView,传递一个CAImage对象作为显示内容。

 

virtual void setImageAsyncWithFile(const char* fileName)

返回值:void

参数:

类型

参数名

说明

const char*

fileName

图像名

    解释:采用异步的方式加载指定图像


注意:

CAImageView 并没有继承CAIamge 类,而是继承CAView类(视图类)。即:CAImage类和CAIageView类是两个不同的类。

引擎是通过CAIamge类将图片文件加载到内存成为对象,然后使用CAIamgeView 类对象来读取并显示。


三。创建CAImageView 对象

存在二个方式:createWithImage()setImageAsyncWithFile()。实例代码:

//caimage1
	auto caimage1 = CAImage::create("r/vdo_pause_down.png");

	//CAImage函数
	//打印贴图描述
	//CCLog("Description:%s", caimage1->description());
	打印像素格式
	//CCLog("StringForFormat:%s", caimage1->stringForFormat());
	打印像素位深
	//CCLog("bitsPerPixelForFormat:%d", caimage1->bitsPerPixelForFormat());

	//CAImageView1 create with caimage 
	auto caimageview1 = CAImageView::createWithImage(caimage1);
	caimageview1->setFrame(CCRect(100, 100, caimage1->getContentSize().width, caimage1->getContentSize().height));
	this->getView()->addSubview(caimageview1);

	//异步加载图片 
	CAImageView* caimageview2 = CAImageView::create();
	caimageview2->setFrame(CCRect(100, 200, 40, 40));  //对于frame 属性来说,图片会根据frame的设置放大和缩小,*bounds不会*
	caimageview2->setImageAsyncWithFile("r/vdo_play_down.png");
	this->getView()->addSubview(caimageview2);
	//异步加载图片
	CAImageView* caimageview3 = CAImageView::createWithFrame(CCRect(100, 240, 40, 40));
	caimageview3->setImageAsyncWithFile("r/vdo_play_down2.png");
	this->getView()->addSubview(caimageview3);
	//异步加载图片 坐标为 中心点的坐标
	CAImageView* caimageview4 = CAImageView::createWithCenter(CCRect(145,330,100,100));
	caimageview4->setImageAsyncWithFile("r/vdo_play_down2.png");
//	auto caimage4 = (CAImage*)caimageview4;   没有实现 getContentSize 方法。
//	CCLog("width:%d,height:%d", caimage4->getContentSize().width, caimage4->getContentSize().height); 
	this->getView()->addSubview(caimageview4);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值