Quantcast
Viewing all articles
Browse latest Browse all 10

Scaling / Resizing an Image (Texture2D)

I am trying to scale an image to fit within GUILayer box. The script comes up with an error on the line with NewImageWidth_1 = image_1.width * ImageRatio; "BCE0051: Operator '*' cannot be used with a left hand side of type 'int' and a right hand side of type 'Object'." private var BoxWidth = 350; private var BoxHeight = 400; var image_1 : Texture2D; private var maxImageWidth = BoxWidth-50; private var ImageRatio; private var NewImageWidth_1 = image_1.width; private var NewImageHeight_1 = image_1.height; if(image_1.width > maxImageWidth){ ImageRatio = maxImageWidth / image_1.width; NewImageWidth_1 = image_1.width * ImageRatio; NewImageHeight_1 = image_1.height * ImageRatio; } GUILayout.Box(image_1,[GUILayout.Width(NewImageWidth_1),GUILayout.Height(NewImageHeight_1)]);

Viewing all articles
Browse latest Browse all 10

Trending Articles