使用 ImageMagic 库将图像转换为像素图
我的任务是“将图像读入像素图,然后将其转换为纹理图”。因此,仅对于像素图部分,请听我说完并告诉我我的想法是否正确以及是否有更简单的方法。我正在使用的库文档: http://www.imagemagick.org/Magick++/Documentation.html< /a>
读入图像:
Image myimage;
myimage.read( "myimage.gif" );
我认为这是我需要将“图像”读入的像素图:
GLubyte pixmap[TextureSize][TextureSize][3];
所以我认为我需要一个循环,为每个“像素图”像素索引分配 R、G、B 值相应的“图像”像素索引。我认为循环体是这样的:
pixmap[i][j][0] = myimage.pixelColor(i,j).redQuantum(void);
pixmap[i][j][1] = myimage.pixelColor(i,j).greenQuantum(void);
pixmap[i][j][2] = myimage.pixelColor(i,j).blueQuantum(void);
但我认为上述函数在我需要 GLubytes 的地方返回 Quantums,所以有人可以在这里提供帮助吗?
-- 或者 --
也许我可以使用 OpenIL 来处理像素图和纹理贴图(此处的文档:http://openil.sourceforge.net/tuts/tut_10/index.htm)。你认为我可以简单地按顺序调用这些吗?
ilutOglLoadImage(char *FileName);
ilutOglBindTexImage(ILvoid);
My assignment is to get "images read into pixmaps which you will then convert to texture maps". So for the pixmap part only, hear me out and tell me if I have the right idea and if there's an easier way. Library docs I'm using: http://www.imagemagick.org/Magick++/Documentation.html
Read in image:
Image myimage;
myimage.read( "myimage.gif" );
I think this is the pixmap I need to read 'image' into:
GLubyte pixmap[TextureSize][TextureSize][3];
So I think I need a loop that, for every 'pixmap' pixel index, assigns R,G,B values from the corresponding 'image' pixel indices. I'm thinking the loop body is like this:
pixmap[i][j][0] = myimage.pixelColor(i,j).redQuantum(void);
pixmap[i][j][1] = myimage.pixelColor(i,j).greenQuantum(void);
pixmap[i][j][2] = myimage.pixelColor(i,j).blueQuantum(void);
But I think the above functions return Quantums where I need GLubytes, so can anyone offer help here?
-- OR --
Perhaps I can take care of both the pixmap and texture map by using OpenIL (docs here: http://openil.sourceforge.net/tuts/tut_10/index.htm). Think I could simply call these in sequence?
ilutOglLoadImage(char *FileName);
ilutOglBindTexImage(ILvoid);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
pixelColor(x,y)
返回的量子值复制到ColorRGB
,您将获得标准化的 (0.0,1.0) 颜色值。如果你不必坚持使用 Magick++ 也许你可以尝试 OpenIL,它可以加载你的图像并将其转换为OpenGL 纹理贴图没有太多麻烦。
You can copy the quantum values returned by
pixelColor(x,y)
toColorRGB
and you will get normalized (0.0,1.0) color values.If you don't have to stick with Magick++ maybe you can try OpenIL, which can load and convert your image to OpenGL texture maps without too much hassle.