Hi, I'm trying to figure out how to slice images at runtime for a project i'm doing on iOS. Here's a screenshot of what i'm trying to achieve: Since i'm using Mobilepaint to draw on a canvastexure, i'm using it's function to return the canvas i'm drawing on to a Texture2D. Here's my code so far: Code (CSharp): using UnityEngine; using UnityEngine.UI; using System.Collections; using unitycoder_MobilePaint; public class SliceDrawing : MonoBehaviour { public MobilePaint mobilePaint; public Image testImage; public void startSlicing() { Texture2D drawingTex = mobilePaint.GetCanvasAsTexture (); print ("Tex height: " + drawingTex.height + " Screen height: " + Screen.height); print ("Tex width: " + drawingTex.width + " Screen width: " + Screen.width); Rect testRect = new Rect (0, 0, 455, Screen.height); Sprite sprite = Sprite.Create (drawingTex, testRect, Vector2.zero); testImage.sprite = sprite; testImage.SetNativeSize (); } } So far it does seem to work but the image is smaller then my TestImage (which is the same size as the size of place number 3). All the sizes seem to be correct (Tex height & width are the same as Screen height and width). Also whenever I try to set the correct size of the testRect or try to set the sprite to the testImage size, Unity3D throws an error saying it can't create a textures bigger than the screensize. Anyone have an idea how to get this working?
So i've played around with some coding an read alot online about the issue I'm having. It seems that cropping is the right name for my problem So here's my code which keeps throwing an error on creating a sprite: !hasError Code (CSharp): using UnityEngine; using UnityEngine.UI; using System.Collections; using unitycoder_MobilePaint; public class SliceDrawing : MonoBehaviour { //The plugin which paints on a canvas public MobilePaint mobilePaint; //crop parts (reference images to get the size and position where the cropping has to be done) public Image topCropPart; public Image bottomCropPart; public Image leftCropPart; public Image rightCropPart; public void startSlicing() { Texture2D drawingTex = mobilePaint.GetCanvasAsTexture (); print(leftCropPart.GetComponent<CanvasRenderer> ().transform.position); Transform trans = leftCropPart.GetComponent<CanvasRenderer> ().transform; int x = (int)trans.position.x; int y = (int)trans.position.y; int width = (int)trans.localScale.x; int height = (int)trans.localScale.y; Color[] pixels = drawingTex.GetPixels (x, y, width, height, 0); print("Pos: x: " + x + " y: " + y + " Width: " + width + " Height: " + height); Texture2D cropped = new Texture2D (width, height, TextureFormat.ARGB32, false); cropped.SetPixels (0, 0, cropped.width, cropped.height, pixels, 0); cropped.Apply (); // Place the left crop result in the right image to see the result Sprite sprite = Sprite.Create (drawingTex, leftCropPart.rectTransform.rect, Vector2.zero); rightCropPart.sprite = sprite; rightCropPart.SetNativeSize (); } }