简体   繁体   English

C ++图像处理

[英]C++ Image Manipulation

So I have made this program for a game and need help with making it a bit more automatic. 所以我为游戏制作了这个程序,需要帮助才能让它更加自动化。

The program takes in an image and then displays it. 该程序接收图像然后显示它。 I'm doing this over textures in OpenGL. 我在OpenGL中对纹理这样做。 When I take the screenshot of the game it is usually something about 700x400. 当我拍摄游戏截图时,它通常是700x400左右。 I input the height and width into my program, resize the image to 1024x1024 (making it a POT texture for better compatibility) by adding blank space (the original image stays at the top left corner and goes all the way to (700,400) and the rest is just blank; does anyone know the term for this?) and then load it into my program and adjust the corners so only the part from (0,0) to (700,400) is shown. 我将高度和宽度输入到我的程序中,通过添加空白区域将图像大小调整为1024x1024(使其成为POT纹理以获得更好的兼容性)(原始图像保留在左上角并一直向(700,400)和休息只是空白;有人知道这个术语吗?)然后将它加载到我的程序中并调整角落,这样只显示从(0,0)到(700,400)的部分。

That's how I handle the display of the image. 这就是我处理图像显示的方式。 Now, I would like to make this automatic. 现在,我想自动完成。 So I'd take a 700x400 picture, pass it to the program which would get the image's width and height (700x400), resize it to 1024x1024 by adding blank space and then load it. 所以我需要一张700x400的图片,将其传递给程序,该程序将获得图像的宽度和高度(700x400),通过添加空格将其大小调整为1024x1024,然后加载它。

So does anyone know a C++ library capable of doing this? 那么有谁知道能够做到这一点的C ++库? I would still be taking the screenshot manually though. 我仍然会手动拍摄截图。

I am using the Simple OpenGL Image Library (SOIL) for loading the picture (.bmp) and converting it into a texture. 我正在使用Simple OpenGL图像库(SOIL)来加载图片(.bmp)并将其转换为纹理。

Thanks! 谢谢!

You don't really have to resize by adding blank space to display image properly. 您不必通过添加空格来正确显示图像来调整大小。 In fact, it's really unefficient way to do it, especially because you store images in .bmp format. 事实上,这是非常有效的方法,特别是因为您以.bmp格式存储图像。

SOIL is able to automatically add the blank space when loading textures - maybe just try to load the file as-is, without doing any operations. SOIL能够在加载纹理时自动添加空格 - 也许只是尝试按原样加载文件,而不进行任何操作。

From SOIL Documentation: 来自SOIL文档:

Can automatically rescale the image to the next largest power-of-two size 可以自动将图像重新缩放到下一个最大的二次幂大小

Can load rectangluar textures for GUI elements or splash screens (requires GL_ARB/EXT/NV_texture_rectangle) 可以为GUI元素或启动画面加载rectangluar纹理(需要GL_ARB / EXT / NV_texture_rectangle)

Anyway, you don't have to use texture to display pixels on the screen. 无论如何,您不必使用纹理来在屏幕上显示像素。 I presume you aren't using shaders for rendering - if it all goes through fixed pipeline, there's glDrawPixels function, which will be much simpler. 我假设你没有使用着色器进行渲染 - 如果它全部通过固定管道,那么glDrawPixels函数会更加简单。 Just remember to change your SOIL call to SOIL_load_image . 只需记住将SOIL调用更改为SOIL_load_image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM