Image::loadRawData error
Posted: Thu Mar 14, 2019 9:09 am
Hey there,
I have a images with different widths and heights I want to add them to a Ogre::TexturePtr texture. This worked so far for some images for me which all had the same size. However when using imgs of different sizes I get this runtime error:
I currently use:
any ideas how I have to adapt my textureFromImage method?
I have a images with different widths and heights I want to add them to a Ogre::TexturePtr texture. This worked so far for some images for me which all had the same size. However when using imgs of different sizes I get this runtime error:
Code: Select all
[ WARN] [1552550498.076344280]: OGRE EXCEPTION(2:InvalidParametersException): Stream size does not match calculated image size in Image::loadRawData at /build/ogre-1.9-mqY1
wq/ogre-1.9-1.9.0+dfsg1/OgreMain/src/OgreImage.cpp (line 283)
terminate called after throwing an instance of 'Ogre::InvalidParametersException'
what(): OGRE EXCEPTION(2:InvalidParametersException): Stream size does not match calculated image size in Image::loadRawData at /build/ogre-1.9-mqY1wq/ogre-1.9-1.9.0+dfs
g1/OgreMain/src/OgreImage.cpp (line 283)
Code: Select all
Ogre::TexturePtr texture = textureFromImage(tile.image(), "texture_" + name_suffix) ;
Code: Select all
Ogre::TexturePtr textureFromImage(const QImage &image,
const std::string &name) {
// convert to 24bit rgb
QImage converted = image.convertToFormat(QImage::Format_RGB888).mirrored();
// create texture
Ogre::TexturePtr texture;
Ogre::DataStreamPtr data_stream;
data_stream.bind(new Ogre::MemoryDataStream((void *)converted.constBits(),
converted.byteCount()));
const Ogre::String res_group =
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
Ogre::TextureManager &texture_manager = Ogre::TextureManager::getSingleton();
// swap byte order when going from QImage to Ogre
texture = texture_manager.loadRawData(name, res_group, data_stream,
converted.width(), converted.height(),
Ogre::PF_B8G8R8, Ogre::TEX_TYPE_2D, 0);
return texture;
}