Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by 5c4r3cr0w · Jul 22, 2016 at 06:11 AM · cameratexturerectreadpixelscrop

Help with cropping a part of an Image using rect.

Hello everyone, I am trying to crop an Image set on a quad using another quad's vertices as Rect. The problem I'm facing is that rect gets offset somehow and not able to capture the exact cropped image.

Here is waht it looks like first image.!

But after it get cropped it looks like second image!

Here is What I have done so far

     public Transform imageQuadTrans;
     public Renderer imageQuad;
     public Renderer LipsMapper;
     Texture2D face, lips;
 
     public Bounds bounds;
 
 
     void Start ()
     {
         face = imageQuad.material.mainTexture as Texture2D;
 
         StartCoroutine (CaptureFrame ());
 
     }
 
 
 
     IEnumerator CaptureFrame ()
     {
         yield return new WaitForEndOfFrame ();
         bounds = LipsMapper.bounds;
         Vector3 topRight = bounds.max;
         Vector3 bottomLeft = bounds.min;
         Vector3 topLeft = new Vector3 (bottomLeft.x, topRight.y, topRight.z);
         Vector3 bottomRight = new Vector3 (topRight.x, bottomLeft.y, bottomLeft.z);
 
 
         Vector3 screenTopR = Camera.main.WorldToScreenPoint (topRight);
         Vector3 screenTopL = Camera.main.WorldToScreenPoint (topLeft);
         Vector3 screenBotR = Camera.main.WorldToScreenPoint (bottomRight);
         Vector3 screenBotL = Camera.main.WorldToScreenPoint (bottomLeft);
 
         Texture2D newTex = new Texture2D (128, 128, TextureFormat.ARGB32, false);
 
         newTex.ReadPixels (new Rect (screenBotL.x, screenBotR.y, Screen.width - screenBotR.x, 0 + screenTopL.y), 0, 0, false);
         
         newTex.Apply ();
         LipsMapper.material.mainTexture = newTex;
     }
 }

Any help regarding this is highly appriciated.. Thank you.

snap-2.png (269.9 kB)
snap-1.png (268.8 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image saschandroid · Jul 22, 2016 at 06:56 AM 0
Share

Are you probably using WorldToScreenPoint in the wrong way? In WorldToScreenPoint "The z position is in world units from the camera." For example if the camera is at z=-10 and your object at z=2 you have to insert z=12 (and not just the z-value of the object).

avatar image 5c4r3cr0w saschandroid · Jul 22, 2016 at 07:40 AM 0
Share

Thanks for your quick reply.

I tried appliying your solution but still get same issue. And I forgot to mention that I'm using an orthographic camera so z value can be anything.

avatar image 5c4r3cr0w · Jul 22, 2016 at 12:30 PM 0
Share

Update

I have found a way to crop image but it adds extra area in quad. Can anyone tell me how to fix this.

Thanks..!

texture2d.png (25.1 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by 786dheeraj · Mar 14, 2017 at 09:20 AM

Did you find any solution? I am also stuck in a similar problem.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

86 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to cut a rectangular area from ui image 1 Answer

Unity generate a sprite with main camera dimentions 0 Answers

Hello.I use the Region Capture to create the coloring of augmented reality. 0 Answers

AR Camera Projection 0 Answers

Convert Texture to Texture2d takes a lot of time in android device. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges