如何jpg和png混和使用,實現mask?
阿新 • • 發佈:2019-02-17
感謝QQ好友(快樂小冬瓜(Dony))的幫忙,問題解決了,解決方法在下面。同時本人剛入行半個月,希望能認識更多的朋友,歡迎加*****:346271116
CCImage *jpgImage = new CCImage();
jpgImage -> initWithImageFile("img/right_1.jpg",CCImage::kFmtJpg);
unsigned char *jpgData = jpgImage -> getData();
CCImage *pngImage = new CCImage();
pngImage -> initWithImageFile("img/right_1_alpha_mask",CCImage::kFmtPng);
unsigned char *pngData = pngImage->getData();
int len = jpgImage->getDataLen();
int width = jpgImage->getWidth();
int height = jpgImage->getHeight();
int pixelSize = len / (width * height);
unsigned char *outPic = new unsigned char[len * 4];
unsigned char dest;
int outIndex = 0;
int srcIndex = 0;
for(int i = 0; i < len; i++)
{
dest = pngData[srcIndex];//得到第一個
outPic[outIndex] = jpgData[srcIndex];
outPic[outIndex + 1] = jpgData[srcIndex + 1];
outPic[outIndex + 2] = jpgData[srcIndex+2];
outPic[outIndex + 3] = dest;
srcIndex += 3;
outIndex += 4;
}
CCTexture2D *texture = new CCTexture2D();
texture->initWithData(outPic,kCCTexture2DPixelFormat_RGBA8888,width,height,CCSizeMake((float)width, (float)height));
CCImage *jpgImage = new CCImage();
jpgImage -> initWithImageFile("img/right_1.jpg",CCImage::kFmtJpg);
unsigned char *jpgData = jpgImage -> getData();
CCImage *pngImage = new CCImage();
pngImage -> initWithImageFile("img/right_1_alpha_mask",CCImage::kFmtPng);
unsigned char *pngData = pngImage->getData();
int len = jpgImage->getDataLen();
int width = jpgImage->getWidth();
int height = jpgImage->getHeight();
int pixelSize = len / (width * height);
unsigned char *outPic = new unsigned char[len * 4];
unsigned char dest;
int outIndex = 0;
int srcIndex = 0;
for(int i = 0; i < len; i++)
{
dest = pngData[srcIndex];//得到第一個
outPic[outIndex] = jpgData[srcIndex];
outPic[outIndex + 1] = jpgData[srcIndex + 1];
outPic[outIndex + 2] = jpgData[srcIndex+2];
outPic[outIndex + 3] = dest;
srcIndex += 3;
outIndex += 4;
}
CCTexture2D *texture = new CCTexture2D();
texture->initWithData(outPic,kCCTexture2DPixelFormat_RGBA8888,width,height,CCSizeMake((float)width, (float)height));