Hi,
I need to send a osg::Image over the network to a c# application, so i thought
to write it into a std::stringstream as jpg or png and send that stream. So i
googled a bit and found this code:
Code:
int main( int argc, char **argv )
{
//osg::ref_ptr<osg::Image> startIm = osgDB::readImageFile("layout.jpg");
osg::ref_ptr<osg::Image> startIm = osgDB::readImageFile("P4110018.jpg");
osgDB::writeImageFile(*startIm, "new.png");
startIm->setPixelFormat(GL_RGB);
//osgDB::writeImageFile(*startIm, "new.jpg");
osg::ref_ptr<osgDB::ReaderWriter> writer =
osgDB::Registry::instance()->getReaderWriterForExtension("jpg");
//osgDB::Registry::instance()->getReaderWriterForExtension("bmp");
if( !writer.valid() )
return -1;
osg::ref_ptr<osgDB::ReaderWriter::Options> op = new
osgDB::ReaderWriter::Options();
op->setOptionString("JPEG_QUALITY 50");
//op->setOptionString("PNG_COMPRESSION 9");
std::stringstream ss;
osgDB::ReaderWriter::WriteResult res = writer->writeImage(*startIm, ss, op);
std::ofstream fout("new.jpg");
fout.clear();
fout << ss.str();
fout.flush();
return 0;
}
and i try it out on my own. I tried it out with multiple file formats. It works
fine for bmp saving. When i try it for jpg or png it doesn't work. writeImage
finishes with FILE_SAVED only if the readImageFile file is the same type as in
writeImage, and even then the output image turns out scrambled and with
switched rows and colors. In other cases the writeImage finishes with
ERROR_IN_WRITING_FILE. Any help is appreciated.
Thank you!
Cheers,
Vedran
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27254#27254
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org