Smooth animation GIF in camera preview

61 views
Skip to first unread message

Talal Shah

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

Hello,

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

unread,
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 (http://ui.perfetto.dev). 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 camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/1c6a1404-d355-4675-a322-c8c0902dbc44n%40android.com.

Talal Shah

unread,
May 31, 2024, 1:52:18 AMMay 31
to Android CameraX Discussion Group, trevor...@google.com, 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 

Glide.with(getApplicationContext()).asGif()
.load(R.drawable.circle_with_transparent)
.apply(requestOptions)
.into(gifOverlay);

<ImageView
android:id="@+id/unverify_gif"
android:layout_width="340dp"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:visibility="visible" />

Trevor McGuire

unread,
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: https://github.com/bumptech/glide/issues/2471

Depending on how complex the animated gif is, you may also see if you can reproduce the gif with animated vector drawables: https://developer.android.com/develop/ui/views/animations/drawable-animation

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
Forward
0 new messages