If you can access the drawing line by line (for example, a bitmap ), the simplest thing you could do is simply downsample , for example, to read only every nth pixel of every nth line.
// n is an integer that is the downsampling factor // width, height are the width and height of the original image, in pixels // down is a new image that is (height/n * width/n) pixels in size for (y = 0; y < height; y += n) { row = ... // read row y from original image into a buffer for (x = 0; x < width; x += n) { down[y/n, x/n] = row[x]; // image[row,col] -- shorthand for accessing a pixel } }
This is a quick and dirty way that allows you to quickly and cheaply change the original image without loading it all into memory. Unfortunately, it also introduces anti-aliasing of the output image (down). Working with aliasing will require interpolation - it is still possible to use the above phased approach, but it is a bit more active.
If you cannot easily access a sequential image, for example. this is JPEG, which encodes data in 8x8 blocks, you can still do something similar to the approach described above. You would just read a line of blocks instead of a line of pixels - the rest of the algorithm would work the same. In addition, if you reduce disqualification by 8 times, then with JPEG - very simple - you just take the DC coefficient for each block . Using this approach, downsampling by multiples of 8 is also possible.
I masked many other details (such as color channels, pixel pitch, etc.), but that should be enough for you to get started.
source share