- Home /
Show only the right most part of the loaded image
Hi. I need to load an image but only show the right most part in the texture. SO far, the code just loads the image to the texture causing the preview to show the compressed version of the image rather than just the right most part.
RawImage ImagePreview;
ImagePreview.enabled = true;
string url = _SavePath + z.ToString() + ".png";
byte [] imageprev = File.ReadAllBytes(url);
texture = new Texture2D(camTexture.width, camTexture.height, TextureFormat.ARGB32, false);
texture.LoadImage(imageprev);
texture.ReadPixels(new Rect (520, 0, 70, texture.height), 0, 0);
texture.Apply();
ImagePreview.texture = texture ;
Answer by DiegoSLTS · May 23, 2016 at 04:41 PM
I don't think RawImage of Texture2D have anything to show just a part of the texture. You can try some of this:
1 - Write some custom component with a different UV mapping than the RawImage (instead of 0,1 in both axis, something like 0,0.5 for x and 0,1 por y)
2 - Maybe you can get the mesh used by RawImage and see if you can change the UV of the vertices.
3 - Create a new Texture that's just the part you want to show from your renderer texture.
4 - Use a mask to hide some part of the RawImage
Answer by ninja_gear · May 23, 2016 at 05:29 PM
Child the 'texture' object in an object with a Mask Component (2d for UI, regular for World) then change the size of the Mask object as/after/before you apply the texture change.
Your answer
Follow this Question
Related Questions
Unity 5.0 Trying to Change the Image - Source Image via Script 3 Answers
Detect WWW Image bitmap dimensions? 2 Answers
Texture2D rotate & translate 0 Answers
How do you download image to UI.Image? 4 Answers