# DrawTexture

> Draw a texture within a rectangle.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.IMGUIModule

## DrawTexture(Rect, Texture)

Draw a texture within a rectangle.

```csharp
public static void DrawTexture(Rect position, Texture image)
```

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to draw the texture within.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display.

### Remarks

Additional Resources: [GUI.color](/engine/6000.6/script-reference/unityengine/gui/color.md), [GUI.contentColor](/engine/6000.6/script-reference/unityengine/gui/contentcolor.md).

### Examples

```csharp
// Draws a texture in the left corner of the screen.
// The texture is drawn in a window 60x60 pixels.
// The source texture is given an aspect ratio of 10x1
// and scaled to fit in the 60x60 rectangle.  Because
// the aspect ratio is preserved, the texture will fit
// inside a 60x10 pixel area of the screen rectangle.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Assign a Texture in the inspector.");
            return;
        }

        GUI.DrawTexture(new Rect(10, 10, 60, 60), aTexture, ScaleMode.ScaleToFit, true, 10.0F);
    }
}
```

## DrawTexture(Rect, Texture, ScaleMode)

Draw a texture within a rectangle.

```csharp
public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode)
```

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to draw the texture within.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display.**** (\[ScaleMode]\(/engine/6000.6/script-reference/unityengine/scalemode)): How to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.

### Remarks

Additional Resources: [GUI.color](/engine/6000.6/script-reference/unityengine/gui/color.md), [GUI.contentColor](/engine/6000.6/script-reference/unityengine/gui/contentcolor.md).

### Examples

```csharp
// Draws a texture in the left corner of the screen.
// The texture is drawn in a window 60x60 pixels.
// The source texture is given an aspect ratio of 10x1
// and scaled to fit in the 60x60 rectangle.  Because
// the aspect ratio is preserved, the texture will fit
// inside a 60x10 pixel area of the screen rectangle.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Assign a Texture in the inspector.");
            return;
        }

        GUI.DrawTexture(new Rect(10, 10, 60, 60), aTexture, ScaleMode.ScaleToFit, true, 10.0F);
    }
}
```

## DrawTexture(Rect, Texture, ScaleMode, bool)

Draw a texture within a rectangle.

```csharp
public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend)
```

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to draw the texture within.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display.**** (\[ScaleMode]\(/engine/6000.6/script-reference/unityengine/scalemode)): How to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Whether to apply alpha blending when drawing the image (enabled by default).

### Remarks

Additional Resources: [GUI.color](/engine/6000.6/script-reference/unityengine/gui/color.md), [GUI.contentColor](/engine/6000.6/script-reference/unityengine/gui/contentcolor.md).

### Examples

```csharp
// Draws a texture in the left corner of the screen.
// The texture is drawn in a window 60x60 pixels.
// The source texture is given an aspect ratio of 10x1
// and scaled to fit in the 60x60 rectangle.  Because
// the aspect ratio is preserved, the texture will fit
// inside a 60x10 pixel area of the screen rectangle.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Assign a Texture in the inspector.");
            return;
        }

        GUI.DrawTexture(new Rect(10, 10, 60, 60), aTexture, ScaleMode.ScaleToFit, true, 10.0F);
    }
}
```

## DrawTexture(Rect, Texture, ScaleMode, bool, float)

Draw a texture within a rectangle.

```csharp
public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect)
```

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to draw the texture within.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display.**** (\[ScaleMode]\(/engine/6000.6/script-reference/unityengine/scalemode)): How to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Whether to apply alpha blending when drawing the image (enabled by default).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Aspect ratio to use for the source image. If 0 (the default), the aspect ratio from the image is used.  Pass in w/h for the desired aspect ratio.  This allows the aspect ratio of the source image to be adjusted without changing the pixel width and height.

### Remarks

Additional Resources: [GUI.color](/engine/6000.6/script-reference/unityengine/gui/color.md), [GUI.contentColor](/engine/6000.6/script-reference/unityengine/gui/contentcolor.md).

### Examples

```csharp
// Draws a texture in the left corner of the screen.
// The texture is drawn in a window 60x60 pixels.
// The source texture is given an aspect ratio of 10x1
// and scaled to fit in the 60x60 rectangle.  Because
// the aspect ratio is preserved, the texture will fit
// inside a 60x10 pixel area of the screen rectangle.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Assign a Texture in the inspector.");
            return;
        }

        GUI.DrawTexture(new Rect(10, 10, 60, 60), aTexture, ScaleMode.ScaleToFit, true, 10.0F);
    }
}
```

## DrawTexture(Rect, Texture, ScaleMode, bool, float, Color, float, float)

Draws a border with rounded corners within a rectangle. The texture is used to pattern the border. Note that this method only works on shader model 2.5 and above.

```csharp
public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect, Color color, float borderWidth, float borderRadius)
```

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to draw the texture within.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display.**** (\[ScaleMode]\(/engine/6000.6/script-reference/unityengine/scalemode)): How to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Whether to apply alpha blending when drawing the image (enabled by default).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Aspect ratio to use for the source image. If 0 (the default), the aspect ratio from the image is used.  Pass in w/h for the desired aspect ratio.  This allows the aspect ratio of the source image to be adjusted without changing the pixel width and height.**** (\[Color]\(/engine/6000.6/script-reference/unityengine/color)): A tint color to apply on the texture.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The width of the border. If 0, the full texture is drawn.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The radius for rounded corners. If 0, corners will not be rounded.

## DrawTexture(Rect, Texture, ScaleMode, bool, float, Color, Vector4, float)

Draws a border with rounded corners within a rectangle. The texture is used to pattern the border. Note that this method only works on shader model 2.5 and above.

```csharp
public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect, Color color, Vector4 borderWidths, float borderRadius)
```

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to draw the texture within.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display.**** (\[ScaleMode]\(/engine/6000.6/script-reference/unityengine/scalemode)): How to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Whether to apply alpha blending when drawing the image (enabled by default).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Aspect ratio to use for the source image. If 0 (the default), the aspect ratio from the image is used.  Pass in w/h for the desired aspect ratio.  This allows the aspect ratio of the source image to be adjusted without changing the pixel width and height.**** (\[Color]\(/engine/6000.6/script-reference/unityengine/color)): A tint color to apply on the texture.**** (\[Vector4]\(/engine/6000.6/script-reference/unityengine/vector4)): The width of the borders (left, top, right and bottom). If Vector4.zero, the full texture is drawn.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The radius for rounded corners. If 0, corners will not be rounded.

## DrawTexture(Rect, Texture, ScaleMode, bool, float, Color, Vector4, Vector4)

Draw a texture within a rectangle.

```csharp
public static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode, bool alphaBlend, float imageAspect, Color color, Vector4 borderWidths, Vector4 borderRadiuses)
```

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to draw the texture within.**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display.**** (\[ScaleMode]\(/engine/6000.6/script-reference/unityengine/scalemode)): How to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Whether to apply alpha blending when drawing the image (enabled by default).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Aspect ratio to use for the source image. If 0 (the default), the aspect ratio from the image is used.  Pass in w/h for the desired aspect ratio.  This allows the aspect ratio of the source image to be adjusted without changing the pixel width and height.**** (\[Color]\(/engine/6000.6/script-reference/unityengine/color)): **** (\[Vector4]\(/engine/6000.6/script-reference/unityengine/vector4)): **** (\[Vector4]\(/engine/6000.6/script-reference/unityengine/vector4)):&#x20;

### Remarks

Additional Resources: [GUI.color](/engine/6000.6/script-reference/unityengine/gui/color.md), [GUI.contentColor](/engine/6000.6/script-reference/unityengine/gui/contentcolor.md).

### Examples

```csharp
// Draws a texture in the left corner of the screen.
// The texture is drawn in a window 60x60 pixels.
// The source texture is given an aspect ratio of 10x1
// and scaled to fit in the 60x60 rectangle.  Because
// the aspect ratio is preserved, the texture will fit
// inside a 60x10 pixel area of the screen rectangle.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Assign a Texture in the inspector.");
            return;
        }

        GUI.DrawTexture(new Rect(10, 10, 60, 60), aTexture, ScaleMode.ScaleToFit, true, 10.0F);
    }
}
```
