Public Group

# 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.

## 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 on other sites
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 on other sites
You could use quads for your characters and then scale them to whatever size you want.

##### 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 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.

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011473
• ### Who's Online (See full list)

There are no registered users currently online

×