Image cropping

Hi,
I am developing an app, but I need some guidance on how to crop an image that was taken from the camera or gallery. I want a drag able box to select part of the image and then place an image/object on top of the image and save it. Any help is much appreciated.

Hi, welcome to the forum!

Both the Texture2D and WebCamTexture classes have functions called GetPixels that can extract a rectangular area of pixels from the texture. Once you have the pixel data, you can create a new texture with the same dimensions as the extracted area and use the SetPixels function to place the pixel data in the new texture. This gives the same overall effect as cropping, although the original texture isn’t modified.

Is there any way to have the user edit or crop their picture? Possibly using a custom shape selector tool (circle or oval)… or anything like that?

I would think that if you create a Rect class object, which on user input, adjusts itself accordingly.

Hi, Do you have solution of this one. I am struck with same problem.

Hi,Did anyone find the solution to this problem.While taking the picture i want to provide image cropping functionality for the user.Below is my code
void Start ()
{
WebCamDevice[ ] devices = WebCamTexture.devices;
deviceName = devices[0].name;
wct = new WebCamTexture(deviceName, Screen.height, Screen.width, 12);
Debug.Log (“Script has been started”);
plane = GameObject.FindWithTag (“Player”);
plane.renderer.material.mainTexture = wct;
// plane.renderer.material.shader = shader;
wct.Play();
//Texture2D Crop= new Texture2D (plane.renderer.material.mainTexture.width,plane.renderer.material.mainTexture.height);
}
public Texture2D heightmap;
public Vector3 size = new Vector3(100, 10, 100);

void OnGUI() {
if (GUI.Button(new Rect(10, 70, 50, 30), “Click”))
TakeSnapshot();
}

// For saving to the _savepath
private string _SavePath = “C:/Images/”; //Change the path here!
int _CaptureCounter = 0;
void TakeSnapshot()
{
Texture2D screen = Application.CaptureScreenshot(“Screenshot123.png”);
Application.CaptureScreenshot(“Screenshot123.png”);

Texture2D snap = new Texture2D(wct.width,wct.height);
//renderer.material.mainTexture = snap;
//snap.SetPixels(wct.GetPixels());
snap.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0);
snap.Apply();
//System.IO.File.WriteAllBytes(_SavePath + _CaptureCounter.ToString() + “.png”,snap.EncodeToPNG());
// ++_CaptureCounter;
}
}
when user takes the picture an oval mask appears to crop the picture and save to the drive,my problem is the background has to be transparent when i take a screenshot.Can anyone help plz

thread over a year old and you necro it

Did someone find a solution ?

Any solution of how to crop the image into the custom shape geometry?

I am looking for the same solution… Andeeeee was on the right track. I think I will continue heading down that road.