|
osg::Image* image = new osg::Image() ;
image = osgDB::readImageFile(filename.c_str());
//读取图像宽和高
unsigned int width_image = image->s();
unsigned int height_image = image->t();
//为new_image分配一个空间
osg::Image* new_image = new osg::Image();
new_image->allocateImage(width_image, height_image, 1, GL_RGBA, GL_FLOAT);
//设置new_image纹理图像数据格式RGBA
new_image->setInternalTextureFormat(GL_RGBA);
//为new_image填充数据
osg::Vec4* dataPtr = (osg::Vec4*)new_image->data();
for( unsigned int i =0; i<width_image; i++)
{
for(unsigned int j=0; j<height_image; j++)
{
osg::Vec4 color_temp = image->getColor( i,j );
//printf("颜色%f%f%f\n",color_temp[0],color_temp[1],color_temp[2]);
*dataPtr++ = color_temp;
}
}
为了操作像素,我先测试:我读取一个图片,然后按像素读取,转存。数据对的,但是顺序是乱的,图像显示是乱的。 |
|