Jump to content
  • Advertisement
Sign in to follow this  
zChrisse

Image shrink algorithm

This topic is 4829 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

Hi! I was wondering how you shrink an image, for example i have a png picture with characters that i use to printtext, the characters are 20x20 pixels. And now i want to be able to write them smaller than that :P I also have a tga loader that i want to be able to shrink the image i load with half or something, just curious what the algorithm are. Do you simply skip one pixel at the time to make it half? Cheers!

Share this post


Link to post
Share on other sites
Advertisement
Usually image shrinking is done with linear or bicubic interpolation. Linear interpolation would just be linear combinations of the pixels that go into the final destination pixel. However, you may want to consider a pre built image zooming library. For example if you use SDL, consider SDL_gfx.

Share this post


Link to post
Share on other sites
You could use quads for your characters and then scale them to whatever size you want.

Share this post


Link to post
Share on other sites
Heh, i dont even know what linear, bicubic interpolation although i did some searching on the net, but i figured i read in to that when i have done more advanced stuff and are more familiar with programming, algorithms and math :)

Anyways i would like to thank you for the fast answer, i tried SDL_gfx as you suggested but havent gotten it to work :)

I'm using Dev-CPP and installed the devpak with the installer in the IDE, after that i include <SDL/SDL_framerate> but i get this error when i try to compile the project:

[Linker error] undefined reference to `_imp__SDL_setFramerate'

i've tried to search the web but havent found anything. Perhaps some of you know ?

Cheers!

Share this post


Link to post
Share on other sites
if you are looking for something simple just take every block of four pixels and average them. Ok imagine that you have a grayscale image, you can have 0 (black) all the way up to 255 (white). Here are four pixels:

200 133
120 87

ok now average them: (200+133+120+87)/4 = 135
So the pixel that represents those four pixels has a value of 135.
This can be used to cut your image from 20x20 to 10x10.
However your images are in color, so what you need to do is average each of the color channels separately. Average the reds with the red, blue and blue, green and green. So in C++ terms that means averaging the bytes that make up your unsigned ints.

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!