Storing RGBA values directly to VTI file for 2D data

I am wondering if it would be possible to store RGBA values into 2D VTI files instead of traditional data values. We are working on something which requires designing Opacity TF based on some criteria and we are trying to do it for 2D data. This is similar to using ParaView, doing a surface rendering and then checking the box to enable opacity function on it. Please let me know if it can be done and is there any example that will allow us to do so.

Yes, it can be done. Just create a 4 component array in your image data.

Thanks Mathieu, it worked!
Just for a reference: When we want to visualize such a file in ParaView, to see the desired result we have to uncheck the Map Scalars option in the Properties window.

Yes indeed.