cocos2d-x  2.1.1

#include <CCImage.h>

Inheritance diagram for CCImage:
CCObject CCCopying

Public Types

enum  EImageFormat {
  kFmtJpg = 0, kFmtPng, kFmtTiff, kFmtRawData,
  kFmtUnKnown
}
 
enum  ETextAlign {
  kAlignCenter = 0x33, kAlignTop = 0x13, kAlignTopRight = 0x12, kAlignRight = 0x32,
  kAlignBottomRight = 0x22, kAlignBottom = 0x23, kAlignBottomLeft = 0x21, kAlignLeft = 0x31,
  kAlignTopLeft = 0x11
}
 

Public Member Functions

 CCImage ()
 
 ~CCImage ()
 
bool initWithImageFile (const char *strPath, EImageFormat imageType=kFmtPng)
 Load the image from the specified path.
 
bool initWithImageFileThreadSafe (const char *fullpath, EImageFormat imageType=kFmtPng)
 
bool initWithImageData (void *pData, int nDataLen, EImageFormat eFmt=kFmtUnKnown, int nWidth=0, int nHeight=0, int nBitsPerComponent=8)
 Load image from stream buffer.
 
bool initWithString (const char *pText, int nWidth=0, int nHeight=0, ETextAlign eAlignMask=kAlignCenter, const char *pFontName=0, int nSize=0)
 Create image with specified string.
 
unsigned char * getData ()
 
int getDataLen ()
 
bool hasAlpha ()
 
bool isPremultipliedAlpha ()
 
bool saveToFile (const char *pszFilePath, bool bIsToRGB=true)
 Save CCImage data to the specified file, with specified format.
 
virtual unsigned short getWidth (void)
 getWidth
 
virtual unsigned short getHeight (void)
 getHeight
 
virtual int getBitsPerComponent (void)
 getBitsPerComponent
 
- Public Member Functions inherited from CCObject
 CCObject (void)
 
virtual ~CCObject (void)
 
void release (void)
 
void retain (void)
 
CCObjectautorelease (void)
 
CCObjectcopy (void)
 
bool isSingleReference (void)
 
unsigned int retainCount (void)
 
virtual bool isEqual (const CCObject *pObject)
 
virtual void update (float dt)
 
- Public Member Functions inherited from CCCopying
virtual CCObjectcopyWithZone (CCZone *pZone)
 

Protected Member Functions

bool _initWithJpgData (void *pData, int nDatalen)
 
bool _initWithPngData (void *pData, int nDatalen)
 
bool _initWithTiffData (void *pData, int nDataLen)
 
bool _initWithRawData (void *pData, int nDatalen, int nWidth, int nHeight, int nBitsPerComponent)
 
bool _saveImageToPNG (const char *pszFilePath, bool bIsToRGB=true)
 
bool _saveImageToJPG (const char *pszFilePath)
 

Protected Attributes

unsigned short m_nWidth
 
unsigned short m_nHeight
 
int m_nBitsPerComponent
 
unsigned char * m_pData
 
bool m_bHasAlpha
 
bool m_bPreMulti
 
- Protected Attributes inherited from CCObject
unsigned int m_uReference
 
unsigned int m_uAutoReleaseCount
 

Additional Inherited Members

- Public Attributes inherited from CCObject
unsigned int m_uID
 
int m_nLuaID
 

Member Enumeration Documentation

Enumerator:
kFmtJpg 
kFmtPng 
kFmtTiff 
kFmtRawData 
kFmtUnKnown 
enum ETextAlign
Enumerator:
kAlignCenter 

Horizontal center and vertical center.

kAlignTop 

Horizontal center and vertical top.

kAlignTopRight 

Horizontal right and vertical top.

kAlignRight 

Horizontal right and vertical center.

kAlignBottomRight 

Horizontal right and vertical bottom.

kAlignBottom 

Horizontal center and vertical bottom.

kAlignBottomLeft 

Horizontal left and vertical bottom.

kAlignLeft 

Horizontal left and vertical center.

kAlignTopLeft 

Horizontal left and vertical top.

Constructor & Destructor Documentation

CCImage ( )
~CCImage ( )

Member Function Documentation

bool _initWithJpgData ( void *  pData,
int  nDatalen 
)
protected
bool _initWithPngData ( void *  pData,
int  nDatalen 
)
protected
bool _initWithRawData ( void *  pData,
int  nDatalen,
int  nWidth,
int  nHeight,
int  nBitsPerComponent 
)
protected
bool _initWithTiffData ( void *  pData,
int  nDataLen 
)
protected
bool _saveImageToJPG ( const char *  pszFilePath)
protected
bool _saveImageToPNG ( const char *  pszFilePath,
bool  bIsToRGB = true 
)
protected
virtual int getBitsPerComponent ( void  )
virtual

getBitsPerComponent

unsigned char* getData ( )
inline
int getDataLen ( )
inline
virtual unsigned short getHeight ( void  )
virtual

getHeight

virtual unsigned short getWidth ( void  )
virtual

getWidth

bool hasAlpha ( )
inline
bool initWithImageData ( void *  pData,
int  nDataLen,
EImageFormat  eFmt = kFmtUnKnown,
int  nWidth = 0,
int  nHeight = 0,
int  nBitsPerComponent = 8 
)

Load image from stream buffer.

Warning
kFmtRawData only supports RGBA8888.
Parameters
pBufferstream buffer which holds the image data.
nLengthdata length expressed in (number of) bytes.
nWidth,nHeight,nBitsPerComponentare used for kFmtRawData.
Returns
true if loaded correctly.
bool initWithImageFile ( const char *  strPath,
EImageFormat  imageType = kFmtPng 
)

Load the image from the specified path.

Parameters
strPaththe absolute file path.
imageTypethe type of image, currently only supporting two types.
Returns
true if loaded correctly.
bool initWithImageFileThreadSafe ( const char *  fullpath,
EImageFormat  imageType = kFmtPng 
)
bool initWithString ( const char *  pText,
int  nWidth = 0,
int  nHeight = 0,
ETextAlign  eAlignMask = kAlignCenter,
const char *  pFontName = 0,
int  nSize = 0 
)

Create image with specified string.

Parameters
pTextthe text the image will show (cannot be nil).
nWidththe image width, if 0, the width will match the text's width.
nHeightthe image height, if 0, the height will match the text's height.
eAlignMaskthe test Alignment
pFontNamethe name of the font used to draw the text. If nil, use the default system font.
nSizethe font size, if 0, use the system default size.
bool isPremultipliedAlpha ( )
inline
bool saveToFile ( const char *  pszFilePath,
bool  bIsToRGB = true 
)

Save CCImage data to the specified file, with specified format.

Parameters
pszFilePaththe file's absolute path, including file suffix.
bIsToRGBwhether the image is saved as RGB format.

Member Data Documentation

bool m_bHasAlpha
protected
bool m_bPreMulti
protected
int m_nBitsPerComponent
protected
unsigned short m_nHeight
protected
unsigned short m_nWidth
protected
unsigned char* m_pData
protected

The documentation for this class was generated from the following files:
  • /Users/zhangkoumyou/SourceCode/cocos2d-x/cocos2dx/platform/CCImage.h
  • /Users/zhangkoumyou/SourceCode/cocos2d-x/cocos2dx/platform/CCImageCommon_cpp.h