Out of memory when changing background image of composer player via api

I am trying to grab camera and display it as the background of composer player, using

SetViewport(\$"");

to change background image in a thread, where currentFile is grabbed from camera.

However, the app will get crashed for out of memory. Is there a way to fix it? I will appreciate for any reply.

SolidworksComposer