Easy function for scaling a bmp image

Hello is there a easy function for scaling a bmp (24 bit) image to a size of 256x256 pixels?
https://en.wikipedia.org/wiki/Image_scaling

Are you scaling up or down? What's the original size?
Last edited on
The original size is not fixed. But the most pictures are bigger, so there is a down scaling.

I am looking for code.
Last edited on
You could perhaps use the CImg library: https://cimg.eu/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// On linux I compiled with libraries: -lX11 -lpthread
#include "CImg.h"
namespace img = cimg_library;

int main() {
    // read in original image
    img::CImg<unsigned char> image("abc.bmp"); // abc.bmp is 1000x1000

    // downsample to 256x256
    image.resize(256, 256, -100, -100, 6); // 6 = Lanczos interpolation

    // write new image
    image.save("abc2.bmp");

    // display image on screen
    //img::CImgDisplay main_disp(image, "Image");
    //while (!main_disp.is_closed()) main_disp.wait();

    return 0;
}

VS Studio don't find the "CImg.h"
Install vcpkg: https://github.com/microsoft/vcpkg#quick-start-windows

install cimg: .\vcpkg install cimg or for 64-bit .\vcpkg install cimg:x64-windows
(to make x64 the default, set the system environment variable VCPKG_DEFAULT_TRIPLET=x64-windows)

Run .\vcpkg\vcpkg integrate install and use in Visual Studio.
Last edited on
Topic archived. No new replies allowed.