NGUI's Prefab Toolbar does this, at edit time even. I recommend checking the code within -- but the idea is simple: create a temporary panel, camera set to use a render texture, instantiate whatever you want rendered into a texture, render it, then destroy the temporary panel, camera and objects.
Yep! Doing that right now. But faced a problem on Android/iOS. We are making a component for complex masks created using UISprite etc. wich are calculated once at start (so it's quite eficient) Think of 9slice masks from atlas sprites etc.
Problem is that masked UITexture with custom shader supports only one UV set (you build a temporary mesh that way and we dont want to hack it).
Resulting rendertexture of mask equals screensize (not square & not power of 2)
Masked UITexture _MainTex & _AlphaTex(from shader) size has to be square and to be power of two on device
So if we dont want to do bilinear\trilinear interpolation on CPU (interpolate rendered mask-widget rect to square pow2 texture2d) we have to change shader and make _AlphaTex to use UV2 so we could manipulate _Alphatex offset&tiling separately from _MainTex.
But.. no UV2 on UITexture and we understand why: small business value + a lot of work.
Maybe you have any other idea? (without NGUI patching/hacking but still elegant?)