Issue with saving overlay on image with ImageJ

Hello all, I’m having a weird issue with flattening an image in ImageJ. I drew a white rectangular outline on an image and it appears fine (attachment 1). However, when I flatten the image the appearance changes (attachment 2). Does anyone know how to retain the white color?
Before flattening:
After flattening:

This is because by default the flattened image is antialiased, see:

Here a JavaScript to disable antialiasing and create a flattened image (execute in the macro editor “Macros->Evaluate JavaScript”):


If it is only for visualization (e.g. presentation) you can alternatively add the selection to the overlay:
Image > Overlay > Add Selection…
or from the ROI Manager:
Image > Overlay > From ROI Manager

then save as .png file.