Hi Adam,

see attached.

jp

Adam Weiss wrote:
Hi,

I'm trying to convert an osg::Image to a PNG file in memory (byte array).  I know 
I could write it to a file, then read it back in, but I was hoping for a more 
direct route.  The goal is to then have another library read in the byte array 
directly.  I tried just using the image->data() function, but the data appears 
to not have a valid image header.

Hopefully, I made my question clear.

Thank you!

Cheers,
Adam

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=18459#18459





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.

/* OpenSceneGraph example, osgcompositeviewer.
*
*  Permission is hereby granted, free of charge, to any person obtaining a copy
*  of this software and associated documentation files (the "Software"), to deal
*  in the Software without restriction, including without limitation the rights
*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*  copies of the Software, and to permit persons to whom the Software is
*  furnished to do so, subject to the following conditions:
*
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
*  THE SOFTWARE.
*/

#include <iostream>
#include <sstream>

#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>


#include <osg/Material>
#include <osg/Geode>
#include <osg/BlendFunc>
#include <osg/Depth>
#include <osg/Projection>
#include <osg/PolygonOffset>
#include <osg/MatrixTransform>
#include <osg/Camera>
#include <osg/FrontFace>

#include <osgText/Text>

#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/StateSetManipulator>
#include <osgViewer/ViewerEventHandlers>

#include <osgViewer/CompositeViewer>

#include <osgFX/Scribe>

#include <osg/io_utils>

#include <osgDB/FileUtils>
#include <osgDB/ReadFile>

int main( int argc, char **argv )
{
    osg::ref_ptr<osg::Image> startIm = osgDB::readImageFile("test.jpg");

    //osgDB::writeImageFile(*startIm, "new.png");
    //osgDB::writeImageFile(*startIm, "new.jpg");

    osg::ref_ptr<osgDB::ReaderWriter> writer = 
        //osgDB::Registry::instance()->getReaderWriterForExtension("jpg");
        osgDB::Registry::instance()->getReaderWriterForExtension("png");

    if( !writer.valid() )
        return -1;

    osg::ref_ptr<osgDB::ReaderWriter::Options> op = new osgDB::ReaderWriter::Options();
    //op->setOptionString("JPEG_QUALITY 75");
    op->setOptionString("PNG_COMPRESSION 9");

    for(int i=0;i<100;i++) {
        std::stringstream ss;
        osgDB::ReaderWriter::WriteResult res = writer->writeImage(*startIm,ss,op);
        std::cout << ss.str().size() << "\n";

        //std::ofstream fout("new.jpg");
        //fout << ss.str();
    }
    return 0;
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to