Recent

Author Topic: Downsampling without antialiasing  (Read 331 times)

Eager

  • New Member
  • *
  • Posts: 16
Downsampling without antialiasing
« on: October 20, 2024, 01:03:57 pm »
Hi all,
I've currently having trouble getting BGRABitmap to resize my image without antialiasing. I have several images of humans than I need to reduce only by a few pixels; if I use Paint.net with "nearest neighbor" interpolation the resized images are crisp and the borders around the figures are deep black.

I haven't been able to find a way to replicate this behavior with BGRABitmap. Even the simplest filter -rmSimpleStretch- adds antialiased/blended borders; looking at the commented code it says it transforms pixels into boxes "with antialiasing between boxes", so maybe this is the reason?

Currently I'm CopyRect'ing each image into a smaller TRect using regular TCanvas methods; as I'm working with a sheet of several hundreds of images this takes a long time. By comparison BGRABitmap's methods are blazingly fast.

Is there any way to disable antialiasing completely and getting a "nearest neighbor" equivalent with BGRABitmap?
Thanks in advance!

domasz

  • Hero Member
  • *****
  • Posts: 553
« Last Edit: October 20, 2024, 01:44:56 pm by domasz »

Eager

  • New Member
  • *
  • Posts: 16
Re: Downsampling without antialiasing
« Reply #2 on: October 20, 2024, 02:31:54 pm »
Canvas.StretchDraw ?

https://forum.lazarus.freepascal.org/index.php/topic,67389.msg518589.html#msg518589

Oh my. Can't believe it was that simple.  %)
I guess I was determined to make it work using the BGRA library... should have asked here earlier. Thank you!!

circular

  • Hero Member
  • *****
  • Posts: 4356
    • Personal webpage
Re: Downsampling without antialiasing
« Reply #3 on: October 22, 2024, 08:04:55 am »
Ah indeed, simple stretch is already kind of antialiased. It could be worth having a "simple stretch without antialising" option. However, indeed, TCanvas stretch draw will do that for you.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018