Skip to content

Instantly share code, notes, and snippets.

@jimfleming
Created December 7, 2014 06:50
Show Gist options
  • Save jimfleming/dcdd481ffec122f40def to your computer and use it in GitHub Desktop.
Save jimfleming/dcdd481ffec122f40def to your computer and use it in GitHub Desktop.
Uses an internal Unity3D utility function to grab chunks of the screen for blurring.
public static class GrabScreenSwatch {
public static Texture GrabScreenSwatch(Rect rect) {
int width = (int)rect.width;
int height = (int)rect.height;
int x = (int)rect.x;
int y = (int)rect.y;
Vector2 position = new Vector2(x, y);
Color[] pixels = UnityEditorInternal.InternalEditorUtility.ReadScreenPixel(position, width, height);
Texture2D texture = new Texture2D(width, height);
texture.SetPixels(pixels);
texture.Apply();
return texture;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment