cocos2D-X create image sprite solution

	int width, height;

	unsigned char *data = SOIL_load_image("06a03.jpg", &width, &height, 0, SOIL_LOAD_RGBA);

	Image *image = new Image();

	//cocos2d::Texture2D::PixelFormat::RGBA8888
	image->initWithRawData(data,width * height,width,height, 2);
	image->setPNGPremultipliedAlphaEnabled(true);
	SOIL_free_image_data(data);

	auto so = Sprite::createWithTexture(Director::getInstance()->getTextureCache()->addImage(image,"key"));
	so->setPosition(display / 2);
	delete image;
	this->addChild(so);
原文地址:https://www.cnblogs.com/YZFHKMS-X/p/12629922.html