What is the fastest way do downscale an image and save it to a stream or a file? lazarus / 39-Graphics ---------------------------------------------------------------------- CM630 · 2017-02-14 08:48 I wonder what is the fastest way do downscale an image and save it to a stream or a file without using external executables (image magic, etc)? I will also need some cropping. All free LPKs are fine. ---------------------------------------------------------------------- Eugene Loza · 2017-02-14 10:05 Well... the fastest down-scale algorithm is "nearest neighbours" which can be additionally optimized in case downscale is fixed (e.g. scale is integer). Cropping can also be done by directly processing the bitmap memory (start here http://wiki.freepascal.org/Developing_with_G raphics#Direct_pixel_access ). If you aren't too crazy about optimizations you might just want to Canvas.CopyRect... The whole thing might look as make a destination bitmap. Scale source bitmap to destination. Save destination to stream. However, such approach doesn't look optimal. If you really want it to be efficient, then I'd advice you to use OpenGL features, however, I use them through Castle Game Engine, so I don't know how to make it without installing additional libraries... ---------------------------------------------------------------------- Handoko · 2017-02-14 10:08 Maybe you can use BGRABitmap, it have scale feature: http://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_11 ---------------------------------------------------------------------- CM630 · 2017-02-22 07:10 Thanks for the hints, I was hoping for some first- hand information. I doubt that there will be any use of OpenGl, since we use Intel VGAs. I will try when possible and feedback. ---------------------------------------------------------------------- Thaddy · 2017-02-22 07:35 Quote from: CM630 on February 14, 2017, 09:48:11 am I wonder what is the fastest way do downscale an image and save it to a stream or a file without using external executables (image magic, etc)? I will also need some cropping. All free LPKs are fine. FPC has bindings for the imagemagic LIBRARIES, no need to call the executable to have the speed of imagemagic. The Imagemagic lib can also be statically linked into your executable and is (at the moment...) still MUCH (4-5 times) faster than any pure pascal solution I know of, including BGRABitmap. Also note that hardware accelerated OpenGL is fully supported by Intel VGA's on ANY platform that supports OpenGL (That includes Windows, Linux and Android)