二楼决解办法
#ifndef VRENDERIMAGE_H
#define VRENDERIMAGE_H
#include “cocos2d.h”
#include “cocostudio/CocoStudio.h”
#include “ui/CocosGUI.h”
USING_NS_CC;
using namespace cocos2d::ui;
class VRenderImage:public RenderTexture
{
public:
VRenderImage(void);
~VRenderImage(void);
static VRenderImage * create(int w, int h, Texture2D::PixelFormat format);
bool saveToImageFile(const std::string& filepath, Image::Format format, bool isRGBA = true, std::function<void (RenderTexture*, const std::string&)> callback = nullptr);
};
#endif
#include “VRenderImage.h”
VRenderImage::VRenderImage(void)
{
}
VRenderImage::~VRenderImage(void)
{
}
VRenderImage * VRenderImage::create(int w, int h, Texture2D::PixelFormat format)
{
VRenderImage *ret = new (std::nothrow) VRenderImage();
if(ret && ret->initWithWidthAndHeight(w, h, format))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
bool VRenderImage::saveToImageFile(const std::string& filepath, Image::Format format, bool isRGBA /= true/, std::function<void (RenderTexture*, const std::string&)> callback /= nullptr/)
{
CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG,
“the image can only be saved as JPG or PNG format”);
if (isRGBA && format == Image::Format::JPG) CCLOG(“RGBA is not supported for JPG format”);
_saveFileCallback = callback;
std::string fullpath = filepath;
_saveToFileCommand.init(_globalZOrder);
_saveToFileCommand.func = CC_CALLBACK_0(VRenderImage::onSaveToFile, this, fullpath, isRGBA);
Director::getInstance()->getRenderer()->addCommand(&_saveToFileCommand);
return true;
}