CopyPixels
Copies pixel data from another texture on the CPU.
Read time 5 minutesLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
CopyPixels(Texture)
Copies pixel data from another texture on the CPU.
public void CopyPixels(Texture src)
Parameters
The source texture.
Remarks
This method copies pixel data from a source texture to this one on the CPU. Texture.isReadable must be for both the texture and , and you must call Texture2DArray.Apply after to upload the changed pixels to the GPU.
truesrcCopyPixelsTexture2DArray.Apply 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 with GraphicsTexture parameters is faster to use instead.
To use , 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.
CopyPixelsCrunch 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 if either texture is unreadable, and throws an if fails.
UnityExceptionArgumentExceptionCopyPixelsCopyPixels(Texture, int, int, int, int)
Copies pixel data from another texture on the CPU.
public void CopyPixels(Texture src, int srcElement, int srcMip, int dstElement, int dstMip)
Parameters
The source texture.
The element in the source texture to copy from. For example, the CubemapFace in a Cubemap or the slice in a texture array. Set the value to if is a 2D texture.
0srcThe mipmap level to copy from. The range is through the source texture's Texture.mipmapCount. The default value is .
00The slice index to copy to in this texture array.
The mipmap level to write to. The range is through this texture's Texture.mipmapCount. The default value is .
00Remarks
This method copies pixel data from a source texture to this one on the CPU. Texture.isReadable must be for both the texture and , and you must call Texture2DArray.Apply after to upload the changed pixels to the GPU.
truesrcCopyPixelsTexture2DArray.Apply 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 with GraphicsTexture parameters is faster to use instead.
To use , 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.
CopyPixelsCrunch 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 if either texture is unreadable, and throws an if fails.
UnityExceptionArgumentExceptionCopyPixelsCopyPixels(Texture, int, int, int, int, int, int, int, int, int, int)
Copies pixel data from another texture on the CPU.
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
The source texture.
The element in the source texture to copy from. For example, the CubemapFace in a Cubemap or the slice in a texture array. Set the value to if is a 2D texture.
0srcThe mipmap level to copy from. The range is through the source texture's Texture.mipmapCount. The default value is .
00The starting x coordinate of to copy from. is the left of the texture.
src0The starting y coordinate of to copy from. is the bottom of the texture.
src0The width of to copy.
srcThe height of to copy.
srcThe slice index to copy to in this texture array.
The mipmap level to write to. The range is through this texture's Texture.mipmapCount. The default value is .
00The x coordinate of this texture to copy to.
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 must be for both the texture and , and you must call Texture2DArray.Apply after to upload the changed pixels to the GPU.
truesrcCopyPixelsTexture2DArray.Apply 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 with GraphicsTexture parameters is faster to use instead.
To use , 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.
CopyPixelsCrunch 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 if either texture is unreadable, and throws an if fails.
UnityExceptionArgumentExceptionCopyPixels