1、格式转换
osg::Image* CommonTools::covertImage(QImage image)
{
QImage glImage = QGLWidget::convertToGLFormat(image);
unsigned char* data = new unsigned char[glImage.byteCount()];
for (int i = 0; i < glImage.byteCount(); i++)
{
data[i] = glImage.bits()[i];
}
osg::Image *markerImage = new osg::Image();
markerImage->setImage(glImage.width(),glImage.height(), 1,4,GL_RGBA,GL_UNSIGNED_BYTE,data,osg::Image::USE_NEW_DELETE,1);
return markerImage;
}
2、保存图片
QImage直接调用save即可
osg::Image需要做如下操作
osg::ref_ptr<osg::Texture2D> texture2d = new osg::Texture2D;
osg::ref_ptr<osg::Image> img = new osg::Image;
img=osgDB::readImageFile("C:\\Users\\Public\\Pictures\\Sample Pictures\\Tulips.jpg");
osg::ref_ptr<osg::Image> img2 = new osg::Image;
img2->setImage(img->s(),img->t(),img->r(),img->getInternalTex