osg学习(三十一)osg、Qt的image

本文介绍了如何在osg和Qt中进行图像处理,包括格式转换、保存图片的操作,详细阐述了QImage和osg::Image在存放顺序上的差异,以及如何处理图像大小和每行长度的问题,强调了避免手动计算,应使用内置函数获取图像信息的重要性。
摘要由CSDN通过智能技术生成

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
OsgEarth 中加载本地 sqlite 瓦片影像地图 png,可以遵循以下步骤: 1. 安装 OsgEarth 和 Qt 库。 2. 创建一个 Qt 应用程序。 3. 在应用程序中添加 OsgEarth 的头文件和库文件。 4. 创建一个 OsgEarth 的 Map 对象,并添加一个 ImageLayer 图层。 5. 设置 ImageLayer 的 DataSourceOptions 属性,使其能够加载本地 sqlite 数据库中的瓦片影像地图 png。 6. 将 Map 对象添加到 OsgViewerQt 控件中。 以下是示例代码: ```cpp #include <osgEarth/Map> #include <osgEarth/MapNode> #include <osgEarth/TileSource> #include <osgEarthQt/ViewerWidget> int main(int argc, char** argv) { // 创建 Qt 应用程序 QApplication app(argc, argv); // 创建 OsgViewerQt 控件 osgEarth::QtGui::ViewerWidget* viewer = new osgEarth::QtGui::ViewerWidget(); // 创建 OsgEarth 的 Map 对象 osgEarth::Map* map = new osgEarth::Map(); // 创建 ImageLayer 图层 osgEarth::ImageLayer* layer = new osgEarth::ImageLayer("MyImageLayer"); // 设置 ImageLayer 的 DataSourceOptions 属性 osgEarth::TileSourceOptions options; options["url"] = "sqlite:///path/to/your/sqlite.db?format=png"; layer->setDataSourceOptions(options); // 添加 ImageLayer 图层到 Map 对象中 map->addImageLayer(layer); // 创建 OsgEarth 的 MapNode 对象 osgEarth::MapNode* mapNode = new osgEarth::MapNode(map); // 将 MapNode 对象添加到 OsgViewerQt 控件中 viewer->setSceneData(mapNode); // 显示 OsgViewerQt 控件 viewer->show(); // 运行 Qt 应用程序 return app.exec(); } ``` 请将代码中的 "/path/to/your/sqlite.db" 替换为你的 sqlite 数据库文件路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值