- Home /
Size of background image for GUI.Box
I have an image with size of 1500x250 pixels and whenever I'm trying to display that image as background of Box with size 300x50 it's not filling all the Box's space. It's like size of image has been set to 150x25 and displayed at center of that box. Maybe I'm doing something wrong? Rect in which that box is being drawn has size of 300x50 pixels as well.
Answer by CHPedersen · Feb 04, 2012 at 03:47 PM
This kind of thing sometimes happens when a GUI element is rendered with its corresponding default GUIStyle. The default GUIStyle for a box has a padding of 4 pixels, which makes the contents (your image) not fill the entire box. I don't know why it seems to be half its size, as you mention, but the padding will cause the centering effect, because it's the same from all four sides.
Try to make a new GUIStyle object just before you render the box, and base it on the default GUIStyle for a box, but change its padding to 0s, and see what happens:
GUIStyle test = new GUIStyle("box");
test.padding = new RectOffset(0,0,0,0);
GUI.Box([your image], test);
Thank you a lot! A style already existed but I didn't knew about that padding stuff.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063728im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I display a flat background - 2D image, not a skybox - behind everything in my camera? 4 Answers
Background image in android manifest 0 Answers
How do I display a background image 1 Answer
UI slider background image 1 Answer
Why can't I see my objects in the scene view when adding a background image and a background camera? 1 Answer