Smooth animation GIF in camera preview

Skip to first unread message

Talal Shah

May 30, 2024, 8:42:34 AMMay 30
to Android CameraX Discussion Group


I am experiencing a performance issue when using a GIF in the camera preview with CameraX. The GIF becomes noticeably laggy when it is included. However, the camera preview operates smoothly when the GIF is not used.

Could you please provide guidance or suggestions on how to resolve this issue?

Trevor McGuire

May 30, 2024, 1:09:27 PMMay 30
to Talal Shah, Android CameraX Discussion Group
Can you provide some more information about how you're showing the GIF in the camera preview? Is this using the CameraEffect API or something else?

It may be necessary to capture some performance traces to figure out exactly what is causing the lag. Perfetto is a good tool for this ( It can also be useful to annotate some of your code with traces using the androidx.tracing library before capturing perfetto traces.

You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Talal Shah

May 31, 2024, 1:52:18 AMMay 31
to Android CameraX Discussion Group,, Android CameraX Discussion Group, Talal Shah
Basically, I want to show a bar animating inside a frame its continuously moving up and down and after scanning I want to show another animation of flipping a card both are lagging with camerax Im using Glide to show animation in camera preview like this. Animation size is 342kb it works fine when I don't use it with camerax 


android:visibility="visible" />

Trevor McGuire

Jun 3, 2024, 1:01:47 PMJun 3
to Talal Shah, Android CameraX Discussion Group
When you say it works fine when you don't use it with CameraX, do you mean when you use it with Camera2 or when you don't use the camera at all?

Image decoding can be a relatively heavyweight operation, and there are certainly factors that can affect performance. In fact, just a quick search of Glide's issues shows this issue which could be related:

Depending on how complex the animated gif is, you may also see if you can reproduce the gif with animated vector drawables:

Ultimately if you want to figure out the performance issue, I would recommend using perfetto to figure out what's really going on. If you can post a minimally reproducing project and the device model you're using to test, I could also take a look.
Reply all
Reply to author
0 new messages