Skip to content

Commit 9c43ad0

Browse files
Store the original alpha channel from the image when creating the ImageMObject and then use it in the set_opacity method (#4313)
Change from PR 2923 by NicoWeio
1 parent ea16d22 commit 9c43ad0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

manim/mobject/types/image_mobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def __init__(
205205
self.pixel_array[:, :, :3] = (
206206
np.iinfo(self.pixel_array_dtype).max - self.pixel_array[:, :, :3]
207207
)
208+
self.orig_alpha_pixel_array = self.pixel_array[:, :, 3].copy()
208209
super().__init__(scale_to_resolution, **kwargs)
209210

210211
def get_pixel_array(self):
@@ -230,8 +231,7 @@ def set_opacity(self, alpha: float) -> Self:
230231
The alpha value of the object, 1 being opaque and 0 being
231232
transparent.
232233
"""
233-
self.pixel_array[:, :, 3] = int(255 * alpha)
234-
self.fill_opacity = alpha
234+
self.pixel_array[:, :, 3] = self.orig_alpha_pixel_array * alpha
235235
self.stroke_opacity = alpha
236236
return self
237237

0 commit comments

Comments
 (0)