blog games developers documentation portfolio gallery

More in this category:

Scale()

void Scale(int width, int height)



(Don't confuse this with Unity's default Texture2D.Resize method, because that only changes the internal pixel size and format, but does not actually resize the contents).

Will scale the image (bilinear) to the new width and height (in pixels). If you want to maintain the image aspect ratio, you will have to take care of that yourself but providing the correct width and height values.

Needless to say that when magnifying a Texture2D, the image quality will diminish.

Example:

if(GUI.Button(new Rect(0,0,200,25), "Scale to 60%")) {
myTexture.Scale(
myTexture.width * 0.6f, // new width 60%
myTexture.height * 0.6f // new height 60%
);
}


Texture2D ScaledCopy(int width, int height)


Same as Scale(), but creates a new texture instead of altering the existing texture. (make sure you destroy the old one when no longer needed).







follow us