how to scale a image file
What exactly do you want to do? Do you want to load a texture and display it? Do you want to save it to another file and reduce its size first?
Nobody can read your thoughts! Give us more information
Nobody can read your thoughts! Give us more information
Hi,
I don´t know if I understand you right...
Do you want to change the picture inside its file so the entire "file" is scaled or do you want to scale the texture when rendering?
For the first case, this has nothing to do with OpenGL because you have to load your picture into the memory where you can change it as you want and write the entire data back into an output-file.
The second case can be achieved by playing around with the texture-coordinates when rendering your triangle / quad / etc. Just adjust the values passed to eg.
I hope that solves your problem.
If not keep on asking :-)
Hope that helped,
Ralph
(edit) oops Case was faster than me :-)
[Edited by - Ekast on November 4, 2007 4:34:09 AM]
I don´t know if I understand you right...
Do you want to change the picture inside its file so the entire "file" is scaled or do you want to scale the texture when rendering?
For the first case, this has nothing to do with OpenGL because you have to load your picture into the memory where you can change it as you want and write the entire data back into an output-file.
The second case can be achieved by playing around with the texture-coordinates when rendering your triangle / quad / etc. Just adjust the values passed to eg.
//assuming the top right vertex of an quad...glTexCoord2f(1.0f, 1.0f);//might be scaled:glTexoord2f(0.5f, 0.5f);
I hope that solves your problem.
If not keep on asking :-)
Hope that helped,
Ralph
(edit) oops Case was faster than me :-)
[Edited by - Ekast on November 4, 2007 4:34:09 AM]
sorry,
i means i have a 1024*1024 image file,
and i want to generate other file image file,which size is 512*512
i means i have a 1024*1024 image file,
and i want to generate other file image file,which size is 512*512
In that case, this has nothing to do with OpenGL.
TBH, the best way to do this is with MS Paint, Photoshop, or another paint program (I recommend Paint.NET if you're looking for a free, Windows-based image editor). Unless you *need* to do this inside of your program, don't.
TBH, the best way to do this is with MS Paint, Photoshop, or another paint program (I recommend Paint.NET if you're looking for a free, Windows-based image editor). Unless you *need* to do this inside of your program, don't.
It's very easy to neatly half the scale of an image. You just make each new pixel the average of the 4 pixels at the same place in the original image:
for (int y = 0; y < halfImage.Height; ++y){ for (int x = 0; x < halfImage.Width; ++x) { halfImage[x][y] = (originalImage[x*2][y*2] + originalImage[x*2 + 1][y*2] + originalImage[x*2][y*2 + 1] + originalImage[x*2 + 1][y*2 + 1]) / 4; }}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement