小图片: IfranView:
IrfanView是免费软件但不开源。下面的程序读入small.png,用最简单的方法放大,然后写入big.png:
/* https://www.nongnu.org/pngpp/ 在libpng上包了C++接口,用起来很方便。 安装与查看libpng++-dev # apt-get install libpng++-dev # dpkg -l | grep libpng ... # dpkg -L libpng++-dev /usr/include/png++ ... # dpkg -L libpng-dev /usr/include/libpng16 /usr/lib/x86_64-linux-gnu/libpng.a ... $ libpng-config --ldflags --cflags -lpng16 -I/usr/include/libpng16 16是版本号 */ #include <png++/image.hpp> // g++ 1.cpp -lpng16 using namespace png; #define RGB rgb_pixel #define ratio 3.14 int main() { image<RGB> small("small.png"); // 打开文件失败会throw const pixel_buffer<RGB>& s = small.get_pixbuf(); int w = small.get_width(), h = small.get_height(); int ww = int(ratio * w + 0.5), hh = (ratio * h + 0.5); image<RGB> big(ww, hh); pixel_buffer<RGB>& b = big.get_pixbuf(); b[0][0] = RGB(255, 128, 0); // 试一下 for (int yy = 0; yy < hh; yy++) { for (int xx = 0; xx < ww; xx++) { int x = int(xx / ratio + 0.5), y = int(yy / ratio + 0.5); if (x >= w) x = w - 1; if (y >= h) y = h - 1; b[yy][xx] = s[y][x]; } } big.write("big.png"); }
效果: 重复IfranView:
lanczos · GitHub Topics | Lanczos resampling - Detailed Pedia
双线性插值 | Bilinear interpolation - Detailed Pedia
Source Code for Smooth Image Resampling [fairly-well-optimized, MMX加普通版, MMX LOOP - about 32% faster]
Plain C Resampling DLL - CodeProject
标签:get,int,big,读写,small,PNG,libpng,放入,png From: https://www.cnblogs.com/funwithwords/p/17034329.html