标签:图片裁切
游戏要用动画,美工还没做出来,于是,从网上找来了几张图,不过图是JavaME时代的图,动画都是靠裁切来显示的,于是想将大图分割成小图来用。
图片规格:图中每个小图的大小是相等的,基本上都是正行,整列的。
上代码:
const char * CutNormalImage::IMAGE_FORMAT_NAME = "image_ (%d).png" ; const char * pSaveImageFromar = "image_%d_%d_%d.png" ; int row = 4 ; int col = 4 ; int begin = 1 ; int end = 116 ; USING_NS_CC ; void CutNormalImage::cutImage() { for (int k = begin ;k <= end ; k++) { const char * pImageName = CCString::createWithFormat(CutNormalImage::IMAGE_FORMAT_NAME,k)->getCString() ; CCSprite* pSprite = CCSprite::create(pImageName); pSprite->setAnchorPoint(ccp(0,0)); float width = pSprite->getContentSize().width / col ; float height = pSprite->getContentSize().height / row ; for (int i = 0 ; i < row ;i++) { for (int j = 0 ;j < col ;j++) { float x = j * width ; float y = i * height ; CCSprite * pCell = CCSprite::create(pImageName,CCRectMake(x,y,width,height)) ; pCell->setAnchorPoint(ccp(0,0)) ; const char* pName = CCString::createWithFormat(pSaveImageFromar,k,i ,j)->getCString() ; CCRenderTexture* rrt = CCRenderTexture::create(width,height); rrt->clear(0,0,0,0); rrt->begin(); pCell ->visit(); rrt->end(); CCImage *pImage = rrt->newCCImage(true); std::string fullpath = CCFileUtils::sharedFileUtils()->getWritablePath() + pName; pImage->saveToFile(fullpath.c_str(), false); } } } }
标签:图片裁切
原文地址:http://blog.csdn.net/c_boy_lu/article/details/44836305