Extension methods for UnityEngine.Texture
and UnityEngine.Color
.
More...
Static Public Member Functions | |
static bool | IsEncodable (this Texture2D texture) |
Determine if the texture is able to encode to PNG or JPG. More... | |
static string | SaveFile (this Texture2D texture, string path) |
Save a UnityEngine.Texture2D , with supported format and readable flag, to a file. More... | |
static void | SetPixels (this Texture2D texture, RenderTexture source) |
Set pixels from given UnityEngine.RenderTexture source. More... | |
static void | SetPixels (this Texture2D texture, Camera camera, int depthBuffer=24, int antiAliasing=1) |
Set pixels from given UnityEngine.Camera source. More... | |
static RenderTextureFormat | GetReadableFormat (this Texture2D texture) |
Get the UnityEngine.RenderTextureFormat by given texture format. More... | |
static TextureFormat | GetReadableFormat (this RenderTexture texture) |
Get the UnityEngine.TextureFormat by given render texture format. More... | |
static Color32[] | GetPixels32 (this RenderTexture texture) |
Get a block of pixel colors. More... | |
static Color[] | GetPixels (this RenderTexture texture) |
Get a block of pixel colors. More... | |
static void | SetPixels32 (this RenderTexture texture, Color32[] colors) |
Set a block of pixel colors. More... | |
static void | SetPixels (this RenderTexture texture, Color[] colors) |
Set a block of pixel colors. More... | |
static void | SetPixels (this RenderTexture texture, Camera camera) |
Set pixels from given UnityEngine.Camera source. More... | |
static void | Resize (this RenderTexture texture, int width, int height) |
Resize the UnityEngine.RenderTexture with the new width and height. More... | |
static void | Clear (this RenderTexture texture) |
Clear the content of the UnityEngine.RenderTexture . More... | |
static void | Flip (this Color[] colors, int width, bool horizontal, bool vertical) |
Flip image colors by the specified axes and width, this will modify the original array sorting. More... | |
static void | Flip (this Color32[] colors, int width, bool horizontal, bool vertical) |
Flip image colors by the specified axes and width, this will modify the original array sorting. More... | |
static Color[] | GetPartial (this Color[] colors, int width, Rect rect) |
Get partial colors within the rect inside image pixel size. More... | |
static Color32[] | GetPartial (this Color32[] colors, int width, Rect rect) |
Get partial colors within the rect inside image pixel size. More... | |
static Color[] | GetScaled (this Color[] colors, int width, Vector2 size) |
Get the colors of scaled image with antialiasing. More... | |
static Color | GetBlurred (this Color[] colors, int width, Vector2 center, Vector2 extend) |
Get blurred color at the specified position in image colors. More... | |
Extension methods for UnityEngine.Texture
and UnityEngine.Color
.
|
static |
Determine if the texture is able to encode to PNG or JPG.
Note, this only checks the texture format, not check the readable flag. Unity will throw exception if not readable, but only log if format wrong when encode.
texture | Texture. |
true
if is encodable; otherwise, false
.
|
static |
Save a UnityEngine.Texture2D
, with supported format and readable flag, to a file.
Encode to JPG if the file path ends with ".jpg" extension, otherwise to PNG. Note, this directly overwrite original file if exists.
texture | Texture. |
path | File path. |
|
static |
Set pixels from given UnityEngine.RenderTexture
source.
As Texture2D.SetPixels()
, you should make sure the size fit. To get a screenshot by assigning RenderTexture.active
. This doesn't call Texture2D.Apply()
.
texture | Texture. |
source | Source texture. |
|
static |
Set pixels from given UnityEngine.Camera
source.
Passing through rendering into temporary UnityEngine.RenderTexture
. This doesn't call Texture2D.Apply()
.
texture | Texture. |
camera | Source camera. |
depthBuffer | Depth buffer bits, allows 0, 16 or 24 only. |
antiAliasing | Anti-aliasing, allows 1, 2, 4 or 8 only. |
|
static |
Get the UnityEngine.RenderTextureFormat
by given texture format.
Used to create UnityEngine.RenderTexture
for this to read pixels from.
texture | Texture. |
UnityEngine.RenderTextureFormat
.
|
static |
Get the UnityEngine.TextureFormat
by given render texture format.
Used to create UnityEngine.Texture2D
to read pixels from this.
texture | Texture. |
UnityEngine.TextureFormat
.
|
static |
Get a block of pixel colors.
Process pass through UnityEngine.Texture2D
in fact.
texture | Texture. |
|
static |
Get a block of pixel colors.
Process pass through UnityEngine.Texture2D
in fact.
texture | Texture. |
|
static |
Set a block of pixel colors.
Process pass through UnityEngine.Texture2D
in fact.
texture | Texture. |
colors | Source colors. |
|
static |
Set a block of pixel colors.
Process pass through UnityEngine.Texture2D
in fact.
texture | Texture. |
colors | Source colors. |
|
static |
Set pixels from given UnityEngine.Camera
source.
Temporary set as target texture to render into.
texture | Texture. |
camera | Source camera. |
|
static |
Resize the UnityEngine.RenderTexture
with the new width and height.
texture | Texture. |
width | New width. |
height | New height. |
|
static |
Clear the content of the UnityEngine.RenderTexture
.
texture | Texture. |
|
static |
Flip image colors by the specified axes and width, this will modify the original array sorting.
colors | Color array. |
width | Image width. |
horizontal | Horizontal. |
vertical | Vertical. |
|
static |
Flip image colors by the specified axes and width, this will modify the original array sorting.
colors | Color array. |
width | Image width. |
horizontal | Horizontal. |
vertical | Vertical. |
|
static |
Get partial colors within the rect inside image pixel size.
You can use Rect.NormalizedToPoint()
to convert the rect from UV space in need.
colors | Color array. |
width | Image width. |
rect | Partial rect. |
|
static |
Get partial colors within the rect inside image pixel size.
You can use Rect.NormalizedToPoint()
to convert the rect from UV space in need.
colors | Color array. |
width | Image width. |
rect | Partial rect. |
|
static |
Get the colors of scaled image with antialiasing.
This cost performance, not to use too often.
colors | Color array. |
width | Image width. |
size | New size. |
|
static |
Get blurred color at the specified position in image colors.
Calculate average color surround center within extend range.
colors | Color array. |
width | Image width. |
center | Center position. |
extend | Extend size. |