Reduces amount of used memory during PNG creation.

Addition to #5147