Jump to content
  • Advertisement
Sign in to follow this  
zny_sssa2000

how to scale a image file

This topic is 3910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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

Share this post


Link to post
Share on other sites
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.

//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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;
}
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!