How to get a Rect from Image or RectTranform?

I need to take screen shoot of specific area of my UI, so I need a Rect to use in Texture2D.ReadPixel().

I tried to put an Image on the RectTranform and a script like this:

 Rect data=Image.GetPixelAdjustedRect();    

//then draw it with        

     void OnGUI()

The result :(the white box is what I’m trying to capture, you can see the darker GUI draw on the upper left)

alt text

Im also tried to use RectTranform.GetWorldCorners() and Camera.WorldToScreenPoint() to create a Rect but no luck even it seem closer :((

alt text

Please help!


You can use RectTransform.rect to get the rect of any RectTransform object. for more details see RectTransform - Unity Scripting.

NOTE: you have to be careful about one thing that it returns the “rectangle in the local space of the Transform”.