Ejemplo n.º 1
0
bool CCRenderTexture::saveBuffer(const char *fileName, int format)
{
	bool bRet = false;
	CCAssert(format == kCCImageFormatJPG || format == kCCImageFormatPNG,
			 "the image can only be saved as JPG or PNG format");

	CCImage *pImage = new CCImage();
	if (pImage != NULL && getUIImageFromBuffer(pImage))
	{
		std::string fullpath = CCFileUtils::getWriteablePath() + fileName;
		if (kCCImageFormatPNG == format)
		{
			fullpath += ".png";
		}
		else
		{
			fullpath += ".jpg";
		}
		
		bRet = pImage->saveToFile(fullpath.c_str());
	}

	CC_SAFE_DELETE(pImage);

	return bRet;
}
Ejemplo n.º 2
0
bool CCRenderTexture::saveBuffer(const char *szFilePath, int x, int y, int nWidth, int nHeight)
{
    bool bRet = false;

    CCImage *pImage = new CCImage();
    if (pImage != NULL && getUIImageFromBuffer(pImage, x, y, nWidth, nHeight))
    {
        bRet = pImage->saveToFile(szFilePath);
    }

    CC_SAFE_DELETE(pImage);
    return bRet;
}
Ejemplo n.º 3
0
bool CCRenderTexture::saveToFile(const char *szFilePath)
{
    bool bRet = false;

    CCImage *pImage = newCCImage();
    if (pImage)
    {
        bRet = pImage->saveToFile(szFilePath, kCCImageFormatJPEG);
    }

    CC_SAFE_DELETE(pImage);
    return bRet;
}
Ejemplo n.º 4
0
bool CCRenderTexture::saveBuffer(int format, const char *fileName, int x, int y, int nWidth, int nHeight)
{
    bool bRet = false;
    CCAssert(format == kCCImageFormatJPG || format == kCCImageFormatPNG,
             "the image can only be saved as JPG or PNG format");

    CCImage *pImage = new CCImage();
    if (pImage != NULL && getUIImageFromBuffer(pImage, x, y, nWidth, nHeight))
    {
        std::string fullpath = CCFileUtils::getWriteablePath() + fileName;

        bRet = pImage->saveToFile(fullpath.c_str());
    }

    CC_SAFE_DELETE(pImage);

    return bRet;
}
Ejemplo n.º 5
0
bool CCRenderTexture::saveToFile(const char *fileName, tCCImageFormat format)
{
    bool bRet = false;
    CCAssert(format == kCCImageFormatJPEG || format == kCCImageFormatPNG,
             "the image can only be saved as JPG or PNG format");

    CCImage *pImage = newCCImage();
    if (pImage)
    {
        std::string fullpath = CCFileUtils::sharedFileUtils()->getWriteablePath() + fileName;
        
        bRet = pImage->saveToFile(fullpath.c_str(), true);
    }

    CC_SAFE_DELETE(pImage);

    return bRet;
}
Ejemplo n.º 6
0
void CCAsyncSprite::setImage(const char *data, size_t size, const string &url){
    CCImage::EImageFormat format = CCImage::kFmtUnKnown;
    size_t pos = url.find_last_of('.');
    if (pos != string::npos) {
        string ext = url.substr(pos, url.size()+1);
        if (ext.compare(".png") == 0|| ext.compare(".PNG") == 0) {
            format = CCImage::kFmtPng;
        }
        else if (ext.compare(".jpg") == 0|| ext.compare(".JPG") == 0 || ext.compare(".jpeg") ||ext.compare(".JPEG") == 0){
            format = CCImage::kFmtJpg;
        }
        if (format != CCImage::kFmtUnKnown) {
            
            CCImage* img = new CCImage;
            img->initWithImageData((void*)data, (long)size, format);
            
            setSpriteWithCCImage(img);
            img->saveToFile((CCFileUtils::sharedFileUtils()->getWritablePath()+m_strFileName).c_str());
        }
    }
}
Ejemplo n.º 7
0
void* downloadToSave(void* ppCurl)
{
	tileData* pData = (tileData*)ppCurl;

	pData->nTryTime--;
	pData->pRawTile;

	CCString strUrl = pData->pMaker->getMapStrategy()->getUrl(pData->pRawTile->x,pData->pRawTile->y,pData->pRawTile->z);

	std::string strResponse;

	CURLcode res;
	CURL* curl = curl_easy_init();

	curl_easy_setopt(curl, CURLOPT_URL, strUrl.getCString());
	curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31");
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteImageData);
	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
	curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);

	res = curl_easy_perform(curl);

	int retcode = 0;  
	res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE , &retcode);
	double length;
	res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD , &length); 

	if (res==CURLE_OK && retcode == 200 && ((int)length)>0 && strResponse.size()>0)
	{
		CCImage* pImage = new CCImage;
		if(pImage->initWithImageData((void*)strResponse.c_str(),(int)length) == false)
		{
			delete pImage;
			pImage = NULL;

			curl_easy_cleanup(curl);

			if(pData->nTryTime>0)
			{
				pData->nTryTime--;
				pthread_t pid;
				pthread_create(&pid, NULL, downloadToSave, (void*)pData);
			}
			else
			{
				pthread_mutex_lock(&cachemutex);
				pData->pMaker->update(pData->pRawTile);
				pthread_mutex_unlock(&cachemutex );
				delete pData;
				pData = NULL;
			}
		}
		else
		{
			pthread_mutex_lock(&cachemutex);
			pData->pMaker->update(NULL);
			pthread_mutex_unlock(&cachemutex );

			curl_easy_cleanup(curl);

			//////////////////////////////////////////////////////////////////////////
			CCString strPath;
			std::string strRootPath = pData->pMaker->getSavePath();
			strPath.initWithFormat("%s//%d//%d//",strRootPath.c_str(),
				pData->pRawTile->z,pData->pRawTile->y);

			if (!SunFile::IsExist(strPath.getCString(),true))
			{
				SunFile::MkDirEx(strPath.getCString());
			}
			
			CCString strFile;
			strFile.initWithFormat("%s%d.%s",strPath.getCString(),
				pData->pRawTile->x,
				pData->pMaker->getImageType());

			if (!SunFile::IsExist(strFile.getCString(),false))
			{
				std::string strName = pData->pMaker->getImageType();
				if ( strName.compare("tiff")== 0)
				{
					unsigned char* m_pData = pImage->getData();
					int m_nWidth,m_nHeight;
					m_nWidth = m_nHeight = 256;
					unsigned char *pTempData = new unsigned char[m_nWidth * m_nHeight * 3];

					for (int i = 0; i < m_nHeight; ++i)
					{
						for (int j = 0; j < m_nWidth; ++j)
						{
							pTempData[(i * m_nWidth + j) * 3] = m_pData[(i * m_nWidth + j) * 4];
							pTempData[(i * m_nWidth + j) * 3 + 1] = m_pData[(i * m_nWidth + j) * 4 + 1];
							pTempData[(i * m_nWidth + j) * 3 + 2] = m_pData[(i * m_nWidth + j) * 4 + 2];
						}
					}

					save_tiff_rgb(strFile.getCString(),256,256,(const char*)pTempData);
					delete pTempData;
				}
				else
				{
					pImage->saveToFile(strFile.getCString());
				}
			}

			delete pData;
			pData = NULL;
		}

		delete pImage;
		pImage = NULL;
	}
	else
	{
		curl_easy_cleanup(curl);

		if(pData->nTryTime>0)
		{
			pData->nTryTime--;
			pthread_t pid;
			pthread_create(&pid, NULL, downloadToSave, (void*)pData);
		}
		else
		{
			pthread_mutex_lock(&cachemutex);
			pData->pMaker->update(pData->pRawTile);
			pthread_mutex_unlock(&cachemutex );
			delete pData;
			pData = NULL;
		}
	}
	return NULL;
}