cocos jpg alpha_mask png

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; }

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...