# CopyPixels

> Copies pixel data from another texture on the CPU.

## Definition

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

## CopyPixels(Texture)

Copies pixel data from another texture on the CPU.

```csharp
public void CopyPixels(Texture src)
```

### Parameters

**** (\[Texture]\(/engine/6000.0/script-reference/unityengine/texture)): The source texture.

### Remarks

This method copies pixel data from a source texture to this one on the CPU. [Texture.isReadable](/engine/6000.0/script-reference/unityengine/texture/isreadable.md) must be `true` for both the texture and `src`, and you must call [Texture2DArray.Apply](/engine/6000.0/script-reference/unityengine/texture2darray/apply.md) after `CopyPixels` to upload the changed pixels to the GPU.

[Texture2DArray.Apply](/engine/6000.0/script-reference/unityengine/texture2darray/apply.md) is an expensive operation because it copies all the pixels in the texture even if you've only changed some of the pixels, so change as many pixels as possible before you call it. If you only need to copy pixels on the GPU, [Graphics.CopyTexture](/engine/6000.0/script-reference/unityengine/graphics/copytexture.md) with [GraphicsTexture](/engine/6000.0/script-reference/unityengine/rendering/graphicstexture.md) parameters is faster to use instead.

To use `CopyPixels`, the size to be copied must be the same in both textures. Use the region-based overload to specify a smaller region than a full mipmap level.

Crunch compressed texture formats are not supported in the element-based overload. Compressed texture formats are not supported at all for for the region-based overload. Unity throws a `UnityException` if either texture is unreadable, and throws an `ArgumentException` if `CopyPixels` fails.

Additional Resources: [Texture2DArray.Apply](/engine/6000.0/script-reference/unityengine/texture2darray/apply.md), [Graphics.CopyTexture](/engine/6000.0/script-reference/unityengine/graphics/copytexture.md), [Texture2DArray.SetPixels](/engine/6000.0/script-reference/unityengine/texture2darray/setpixels.md).

## CopyPixels(Texture, int, int, int, int)

Copies pixel data from another texture on the CPU.

```csharp
public void CopyPixels(Texture src, int srcElement, int srcMip, int dstElement, int dstMip)
```

### Parameters

**** (\[Texture]\(/engine/6000.0/script-reference/unityengine/texture)): The source texture.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The element in the source texture to copy from. For example, the [CubemapFace](/engine/6000.0/script-reference/unityengine/cubemapface.md) in a Cubemap or the slice in a texture array. Set the value to `0` if `src` is a 2D texture.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The mipmap level to copy from. The range is `0` through the source texture's [Texture.mipmapCount](/engine/6000.0/script-reference/unityengine/texture/mipmapcount.md). The default value is `0`.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The slice index to copy to in this texture array.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The mipmap level to write to. The range is `0` through this texture's [Texture.mipmapCount](/engine/6000.0/script-reference/unityengine/texture/mipmapcount.md). The default value is `0`.

### Remarks

This method copies pixel data from a source texture to this one on the CPU. [Texture.isReadable](/engine/6000.0/script-reference/unityengine/texture/isreadable.md) must be `true` for both the texture and `src`, and you must call [Texture2DArray.Apply](/engine/6000.0/script-reference/unityengine/texture2darray/apply.md) after `CopyPixels` to upload the changed pixels to the GPU.

[Texture2DArray.Apply](/engine/6000.0/script-reference/unityengine/texture2darray/apply.md) is an expensive operation because it copies all the pixels in the texture even if you've only changed some of the pixels, so change as many pixels as possible before you call it. If you only need to copy pixels on the GPU, [Graphics.CopyTexture](/engine/6000.0/script-reference/unityengine/graphics/copytexture.md) with [GraphicsTexture](/engine/6000.0/script-reference/unityengine/rendering/graphicstexture.md) parameters is faster to use instead.

To use `CopyPixels`, the size to be copied must be the same in both textures. Use the region-based overload to specify a smaller region than a full mipmap level.

Crunch compressed texture formats are not supported in the element-based overload. Compressed texture formats are not supported at all for for the region-based overload. Unity throws a `UnityException` if either texture is unreadable, and throws an `ArgumentException` if `CopyPixels` fails.

Additional Resources: [Texture2DArray.Apply](/engine/6000.0/script-reference/unityengine/texture2darray/apply.md), [Graphics.CopyTexture](/engine/6000.0/script-reference/unityengine/graphics/copytexture.md), [Texture2DArray.SetPixels](/engine/6000.0/script-reference/unityengine/texture2darray/setpixels.md).

## CopyPixels(Texture, int, int, int, int, int, int, int, int, int, int)

Copies pixel data from another texture on the CPU.

```csharp
public void CopyPixels(Texture src, int srcElement, int srcMip, int srcX, int srcY, int srcWidth, int srcHeight, int dstElement, int dstMip, int dstX, int dstY)
```

### Parameters

**** (\[Texture]\(/engine/6000.0/script-reference/unityengine/texture)): The source texture.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The element in the source texture to copy from. For example, the [CubemapFace](/engine/6000.0/script-reference/unityengine/cubemapface.md) in a Cubemap or the slice in a texture array. Set the value to `0` if `src` is a 2D texture.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The mipmap level to copy from. The range is `0` through the source texture's [Texture.mipmapCount](/engine/6000.0/script-reference/unityengine/texture/mipmapcount.md). The default value is `0`.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The starting x coordinate of `src` to copy from. `0` is the left of the texture.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The starting y coordinate of `src` to copy from. `0` is the bottom of the texture.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The width of `src` to copy.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The height of `src` to copy.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The slice index to copy to in this texture array.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The mipmap level to write to. The range is `0` through this texture's [Texture.mipmapCount](/engine/6000.0/script-reference/unityengine/texture/mipmapcount.md). The default value is `0`.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The x coordinate of this texture to copy to.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The y coordinate to this texture to copy to.

### Remarks

This method copies pixel data from a source texture to this one on the CPU. [Texture.isReadable](/engine/6000.0/script-reference/unityengine/texture/isreadable.md) must be `true` for both the texture and `src`, and you must call [Texture2DArray.Apply](/engine/6000.0/script-reference/unityengine/texture2darray/apply.md) after `CopyPixels` to upload the changed pixels to the GPU.

[Texture2DArray.Apply](/engine/6000.0/script-reference/unityengine/texture2darray/apply.md) is an expensive operation because it copies all the pixels in the texture even if you've only changed some of the pixels, so change as many pixels as possible before you call it. If you only need to copy pixels on the GPU, [Graphics.CopyTexture](/engine/6000.0/script-reference/unityengine/graphics/copytexture.md) with [GraphicsTexture](/engine/6000.0/script-reference/unityengine/rendering/graphicstexture.md) parameters is faster to use instead.

To use `CopyPixels`, the size to be copied must be the same in both textures. Use the region-based overload to specify a smaller region than a full mipmap level.

Crunch compressed texture formats are not supported in the element-based overload. Compressed texture formats are not supported at all for for the region-based overload. Unity throws a `UnityException` if either texture is unreadable, and throws an `ArgumentException` if `CopyPixels` fails.

Additional Resources: [Texture2DArray.Apply](/engine/6000.0/script-reference/unityengine/texture2darray/apply.md), [Graphics.CopyTexture](/engine/6000.0/script-reference/unityengine/graphics/copytexture.md), [Texture2DArray.SetPixels](/engine/6000.0/script-reference/unityengine/texture2darray/setpixels.md).
