WebP is a new image format that provides lossless and lossy compression for images on the web. WebP lossless images are 28 smaller in size compared to PNGs. WebP lossy images are 25-34 smaller in size compared to JPEG images at equivalent SSIM index. WebP supports losseless transparency (also known as alpha channel) with just 22 additional bytes. WebP also supports features such as animation, ICC color profile, XMP meta-data and tiling.
Webmasters and web developers can use the WebP image format to create smaller and richer images that can help make the web faster.
#include “HelloWorldScene.h”
#include “CCTexture2D.h”
#include “CCImage.h”
USING_NS_CC;
#include <WebP/decode.h>
@CCFileData tmpData(CCFileUtils::fullPathFromRelativePath("test0.webp"), "rb");
unsigned long nSize = 0;
nSize = tmpData.getSize();
unsigned char\* pBuffer = NULL;
pBuffer =tmpData.getBuffer();
// Get the current version of the WebP decoder
int rc = WebPGetDecoderVersion();
printf("Version: d“, rc);
// Get the width and height of the selected WebP image
int width = 0;
int height = 0;
WebPGetInfo(pBuffer, nSize, &width, &height);
printf(”Image Width: d Image Height: d", width, height);
// Decode the WebP image data into a RGBA value array
uint8_t data = WebPDecodeRGBA;
CCImage tmpImage = new CCImage();
bool isOk = tmpImage~~>initWithImageData,width,height,8);
if {
CCTexture2D * tmpText = new CCTexture2D;
tmpText~~>initWithImage(tmpImage);
CCSprite * tmpSprite = CCSprite::spriteWithTexture(tmpText);
tmpSprite~~>setPosition);
this~~>addChild(tmpSprite);
}@
you can copy the WebP.framework into your frameworks
WebP.framework.zip (308.6 KB)