查看: 944|回复: 1

Image生成png为啥写到文件里是没颜色???

[复制链接]

该用户从未签到

发表于 2014-6-5 14:35:18 | 显示全部楼层 |阅读模式
本帖最后由 oirrm 于 2014-6-7 09:36 编辑

  1.     osg::ref_ptr<osg::Image> image = new osg::Image;
  2.         image->setImage(WidthSize,HeightSize,1,
  3.                 GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE,
  4.                 new unsigned char[4* WidthSize *HeightSize],
  5.                 osg::Image::USE_NEW_DELETE);

  6.         unsigned char* ptr = image->data();
  7.         memset(ptr,0,4 * WidthSize * HeightSize);
  8.         for(int i = 0 ; i < HeightSize; i++)
  9.         {
  10.                 for(int j = 0; j <  WidthSize ; j++)
  11.                 {
  12.                         *(ptr ) = 255;
  13.                         *(ptr  + 1) = 0;
  14.                         *(ptr  + 2) = 255;
  15.                         *(ptr  + 3) = 255;
  16.                 }
  17.         }
  18.         osgDB::writeImageFile(*image,"E:\\rect.png");
复制代码

该用户从未签到

发表于 2014-6-25 16:58:59 | 显示全部楼层
您的代码显然是有问题的,赋值的时候ptr从来都没有变化过,所以只是在给第一个像素上色而已
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表