加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos jpg alpha_mask png

发布时间:2020-12-14 16:49:47 所属栏目:百科 来源:网络整理
导读:Texture2D* StartLayer::addJpgMaskPng(const char* jpgName,const char* maskName) { CCImage *jpgImage = new CCImage(); jpgImage-initWithImageFile(jpgName); unsigned char *jpgData = jpgImage-getData(); int lenJPGPerPixel = jpgImage-getBitPerPix
Texture2D* StartLayer::addJpgMaskPng(const char* jpgName,const char* maskName) { CCImage *jpgImage = new CCImage(); jpgImage->initWithImageFile(jpgName); unsigned char *jpgData = jpgImage->getData(); int lenJPGPerPixel = jpgImage->getBitPerPixel() / 8; int width = jpgImage->getWidth(); int height = jpgImage->getHeight(); int len = width * height; CCImage *alphaImage = new CCImage(); alphaImage->initWithImageFile(maskName); unsigned char *alphaData = alphaImage->getData(); int lenAlphaPerPixel = alphaImage->getBitPerPixel() / 8; unsigned char *outPic = new unsigned char[width * height * 4]; int outIndex = 0; int srcIndex = 0; for (int i = 0; i < len; i++) { outPic[outIndex + 0] = jpgData[srcIndex + 0]; outPic[outIndex + 1] = jpgData[srcIndex + 1]; outPic[outIndex + 2] = jpgData[srcIndex + 2]; outPic[outIndex + 3] = alphaData[i*lenAlphaPerPixel]; srcIndex += 3; outIndex += 4; } CCTexture2D *texture = new CCTexture2D(); texture->initWithData(outPic,len * 4,Texture2D::PixelFormat::RGBA8888,width,height,Size((float)width,(float)height)); delete jpgImage; delete alphaImage; delete[] outPic; return texture; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读