本文整理汇总了C++中Codec::codeToFile方法的典型用法代码示例。如果您正苦于以下问题:C++ Codec::codeToFile方法的具体用法?C++ Codec::codeToFile怎么用?C++ Codec::codeToFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Codec
的用法示例。
在下文中一共展示了Codec::codeToFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stream
void Win32Window::writeContentsToFile(const String& filename)
{
ImageCodec::ImageData *imgData = new ImageCodec::ImageData();
imgData->width = mWidth;
imgData->height = mHeight;
imgData->depth = 1;
imgData->format = PF_BYTE_RGB;
// Allocate buffer
uchar* pBuffer = new uchar[mWidth * mHeight * 3];
// Switch context if different from current one
RenderSystem* rsys = Root::getSingleton().getRenderSystem();
rsys->_setViewport(this->getViewport(0));
// Must change the packing to ensure no overruns!
glPixelStorei(GL_PACK_ALIGNMENT, 1);
// Read pixels
// I love GL: it does all the locking & colour conversion for us
if (mIsFullScreen)
glReadBuffer(GL_FRONT);
glReadPixels(0,0, mWidth, mHeight, GL_RGB, GL_UNSIGNED_BYTE, pBuffer);
// restore default alignment
glPixelStorei(GL_PACK_ALIGNMENT, 4);
// Wrap buffer in a memory stream
DataStreamPtr stream(new MemoryDataStream(pBuffer, mWidth * mHeight * 3, false));
// Need to flip the read data over in Y though
Image img;
img.loadRawData(stream, mWidth, mHeight, imgData->format );
img.flipAroundX();
MemoryDataStreamPtr streamFlipped(new MemoryDataStream(img.getData(), stream->size(), false));
// Get codec
size_t pos = filename.find_last_of(".");
String extension;
if( pos == String::npos )
OGRE_EXCEPT(
Exception::ERR_INVALIDPARAMS,
"Unable to determine image type for '" + filename + "' - invalid extension.",
"Win32Window::writeContentsToFile" );
while( pos != filename.length() - 1 )
extension += filename[++pos];
// Get the codec
Codec * pCodec = Codec::getCodec(extension);
// Write out
Codec::CodecDataPtr ptr(imgData);
pCodec->codeToFile(streamFlipped, filename, ptr);
delete [] pBuffer;
}
示例2: save
//-----------------------------------------------------------------------------
void Image::save(const String& filename)
{
if( !mBuffer )
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "No image data loaded",
"Image::save");
}
String strExt;
size_t pos = filename.find_last_of(".");
if( pos == String::npos )
OGRE_EXCEPT(
Exception::ERR_INVALIDPARAMS,
"Unable to save image file '" + filename + "' - invalid extension.",
"Image::save" );
while( pos != filename.length() - 1 )
strExt += filename[++pos];
Codec * pCodec = Codec::getCodec(strExt);
if( !pCodec )
OGRE_EXCEPT(
Exception::ERR_INVALIDPARAMS,
"Unable to save image file '" + filename + "' - invalid extension.",
"Image::save" );
ImageCodec::ImageData* imgData = OGRE_NEW ImageCodec::ImageData();
imgData->format = mFormat;
imgData->height = mHeight;
imgData->width = mWidth;
imgData->depth = mDepth;
imgData->size = mBufSize;
// Wrap in CodecDataPtr, this will delete
Codec::CodecDataPtr codeDataPtr(imgData);
// Wrap memory, be sure not to delete when stream destroyed
MemoryDataStreamPtr wrapper(OGRE_NEW MemoryDataStream(mBuffer, mBufSize, false));
pCodec->codeToFile(wrapper, filename, codeDataPtr);
}