コード例 #1
0
        public static CCData dataWithContentsOfFile(string strPath)
        {
            CCFileData data = new CCFileData(strPath, "rb");
            ulong nSize = data.Size;
            byte[] pBuffer = data.Buffer;

            if (pBuffer == null)
            {
                return null;
            }

            CCData pRet = new CCData();
            pRet.m_pData = pBuffer;
            //memcpy(pRet->m_pData, pBuffer, nSize);

            return pRet;
        }
コード例 #2
0
        public static CCData dataWithContentsOfFile(string strPath)
        {
            CCFileData data  = new CCFileData(strPath, "rb");
            ulong      nSize = data.Size;

            byte[] pBuffer = data.Buffer;

            if (pBuffer == null)
            {
                return(null);
            }

            CCData pRet = new CCData();

            pRet.m_pData = pBuffer;
            //memcpy(pRet->m_pData, pBuffer, nSize);

            return(pRet);
        }
コード例 #3
0
        /* get buffer as UIImage, can only save a render buffer which has a RGBA8888 pixel format */
        public CCData getUIImageAsDataFromBuffer(int format)
        {
            CCData pData = null;

            //@ todo CCRenderTexture::getUIImageAsDataFromBuffer

            // #include "Availability.h"
            // #include "UIKit.h"

            //     GLubyte * pBuffer   = NULL;
            //     GLubyte * pPixels   = NULL;
            //     do
            //     {
            //         CC_BREAK_IF(! m_pTexture);
            //
            //         CCAssert(m_ePixelFormat == kCCTexture2DPixelFormat_RGBA8888, "only RGBA8888 can be saved as image");
            //
            //         const CCSize& s = m_pTexture->getContentSizeInPixels();
            //         int tx = s.width;
            //         int ty = s.height;
            //
            //         int bitsPerComponent = 8;
            //         int bitsPerPixel = 32;
            //
            //         int bytesPerRow = (bitsPerPixel / 8) * tx;
            //         int myDataLength = bytesPerRow * ty;
            //
            //         CC_BREAK_IF(! (pBuffer = new GLubyte[tx * ty * 4]));
            //         CC_BREAK_IF(! (pPixels = new GLubyte[tx * ty * 4]));
            //
            //         this->begin();
            //         glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, pBuffer);
            //         this->end();
            //
            //         int x,y;
            //
            //         for(y = 0; y <ty; y++) {
            //             for(x = 0; x <tx * 4; x++) {
            //                 pPixels[((ty - 1 - y) * tx * 4 + x)] = pBuffer[(y * 4 * tx + x)];
            //             }
            //         }
            //
            //         if (format == kCCImageFormatRawData)
            //         {
            //             pData = CCData::dataWithBytesNoCopy(pPixels, myDataLength);
            //             break;
            //         }

            //@ todo impliment save to jpg or png

            /*
             * CGImageCreate(size_t width, size_t height,
             * size_t bitsPerComponent, size_t bitsPerPixel, size_t bytesPerRow,
             * CGColorSpaceRef space, CGBitmapInfo bitmapInfo, CGDataProviderRef provider,
             * const CGFloat decode[], bool shouldInterpolate,
             * CGColorRenderingIntent intent)
             */
            // make data provider with data.
            //         CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault;
            //         CGDataProviderRef provider		= CGDataProviderCreateWithData(NULL, pixels, myDataLength, NULL);
            //         CGColorSpaceRef colorSpaceRef	= CGColorSpaceCreateDeviceRGB();
            //         CGImageRef iref					= CGImageCreate(tx, ty,
            //             bitsPerComponent, bitsPerPixel, bytesPerRow,
            //             colorSpaceRef, bitmapInfo, provider,
            //             NULL, false,
            //             kCGRenderingIntentDefault);
            //
            //         UIImage* image					= [[UIImage alloc] initWithCGImage:iref];
            //
            //         CGImageRelease(iref);
            //         CGColorSpaceRelease(colorSpaceRef);
            //         CGDataProviderRelease(provider);
            //
            //
            //
            //         if (format == kCCImageFormatPNG)
            //             data = UIImagePNGRepresentation(image);
            //         else
            //             data = UIImageJPEGRepresentation(image, 1.0f);
            //
            //         [image release];
            //     } while (0);
            //
            //     CC_SAFE_DELETE_ARRAY(pBuffer);
            //     CC_SAFE_DELETE_ARRAY(pPixels);
            return(pData);
        }