- Home /
How to change origin of GetPixels
Hello, I've been trying to use Texture2D.GetPixels to only display the middle segment of a (32, 96) texture. While I am able to display up to the full height of GetPixels, it still starts from the bottom/top corner origin, when I actually want to display from (0, 32) to (32,64).
I've tried searching the manual for this (http://docs.unity3d.com/ScriptReference/Texture2D.GetPixels.html) and had the problem mentioned above. Unless I'm just not using it correctly.
Hopefully I've included enough specific information to make this a good question, including a drawing(below) of what I'm trying to make happen, if that helps. Anyways, thanks in advance for any help.
using UnityEngine;
using System.Collections;
public class TextureFramingScript : MonoBehaviour {
public Texture2D sourceTex;
public Rect sourceRect;
void Start()
{
int x = Mathf.FloorToInt(sourceRect.x);
int y = Mathf.FloorToInt(sourceRect.x);
int width = Mathf.FloorToInt(sourceRect.width);
int height = Mathf.FloorToInt(sourceRect.height);
Color[] pix = sourceTex.GetPixels(x, y, width, height);
Texture2D destTex = new Texture2D(width, height);
destTex.SetPixels(pix);
destTex.Apply();
GetComponent<Renderer>().material.mainTexture = destTex;
}
Your answer
Follow this Question
Related Questions
How to get ARGB values from Texture object? 1 Answer
The non-trivial problem with image processing. 1 Answer
Capture screen of other spot 1 Answer
GetPixels of RenderTexture 3 Answers
make pencil just like the lab 0 Answers