Canvas has a function `replace_canvas!(height, width, new_pixels)` that will do this much more efficiently.