本文整理汇总了C++中ofBuffer::getBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ ofBuffer::getBuffer方法的具体用法?C++ ofBuffer::getBuffer怎么用?C++ ofBuffer::getBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofBuffer
的用法示例。
在下文中一共展示了ofBuffer::getBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadImageFromMemory
//----------------------------------------------------
bool ofImage::loadImageFromMemory(const ofBuffer & buffer, ofPixels &pix){
int width, height, bpp;
bool bLoaded = false;
FIBITMAP * bmp = NULL;
FIMEMORY *hmem = NULL;
printf("loadImageFromMemory\n");
hmem = FreeImage_OpenMemory((unsigned char*)buffer.getBuffer(), buffer.size());
if (hmem == NULL){
ofLog(OF_LOG_ERROR,"couldn't create memory handle! \n");
return false;
}
//get the file type!
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem);
if( fif == -1 ){
ofLog(OF_LOG_ERROR,"unable to guess format", fif);
return false;
FreeImage_CloseMemory(hmem);
}
//make the image!!
bmp = FreeImage_LoadFromMemory(fif, hmem, 0);
if( bmp != NULL ){
bLoaded = true;
ofLog(OF_LOG_VERBOSE,"FreeImage_LoadFromMemory worked!\n");
}
//-----------------------------
if (bLoaded){
putBmpIntoPixels(bmp,pix);
} else {
width = height = bpp = 0;
}
if (bmp != NULL){
FreeImage_Unload(bmp);
}
if( hmem != NULL ){
FreeImage_CloseMemory(hmem);
}
return bLoaded;
}
示例2: ofReadFile
//--------------------------------------------------
bool ofReadFile(const string & path, ofBuffer & buffer, bool binary){
ifstream * file = new ifstream(ofToDataPath(path,true).c_str());
if(!file || !file->is_open()){
ofLog(OF_LOG_ERROR, "couldn't open " + path);
return false;
}
filebuf *pbuf=file->rdbuf();
// get file size using buffer's members
long size = (long)pbuf->pubseekoff (0,ios::end,ios::in);
pbuf->pubseekpos (0,ios::in);
// get file data
if(!binary){
buffer.allocate(size+1);// = new char[size];
buffer.getBuffer()[size]='\0';
}else{
buffer.allocate(size);
}
pbuf->sgetn (buffer.getBuffer(),size);
return true;
}