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 334499p · Mar 26, 2016 at 09:45 PM · spritetexture2dwebcamtexturegetpixelssetpixel

WebCamTexture to circular sprite

Hi, I'm creating an application for iOS and android and need to capture a picture to be used as a projectile. The user is displayed a video feed (working) and when they press the video feed a picture will be taken and cut into a circle shape by first converting the picture into a texture2d. When I test it on my phone the video feed works correctly but when I capture the picture and try to make it a circle I receive an output of a gray square.

     void finalizeSpritePicture(){
         if (camTexture != null) {
             IntPtr pointer = camTexture.GetNativeTexturePtr ();
             Texture2D camTexture2D = new Texture2D (256, 256, TextureFormat.ARGB32, false, true);
             camTexture2D.UpdateExternalTexture (pointer);
             camTexture2D = CalculateTexture (camTexture2D);
             profileSprite = Sprite.Create (camTexture2D, new Rect (0, 0, 256, 256), new Vector2 (128, 128));
             profileImage.sprite = profileSprite;
             camTexture.Stop ();
         } else {
             Debug.Log ("Failed to capture picture: No Camera Feed");
         }
     }
 
 
     Texture2D CalculateTexture(Texture2D sourceTexture){
         Color[] c = sourceTexture.GetPixels (0, 0, sourceTexture.width, sourceTexture.height);
         Texture2D b = new Texture2D (256, 256);
         for (int i = 0; i < (256 * 256); i++) {
             int y = Mathf.FloorToInt (((float)i) / ((float)256));
             int x = Mathf.FloorToInt (((float)i - ((float)(y * 256))));
             if (256 * 256 >= (x - 128) * (x - 128) + (y - 128) * (y - 128)) {
                 b.SetPixel (x, y, c [i]);
             } else {
                 b.SetPixel (x, y, Color.clear);
             }
         }
         b.Apply ();
         return b;
 
     }

Please provide help as to why the webcam picture cannot be cut into a circle and turned into a sprite. Thank you!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Andrea_Marchetti · May 27, 2017 at 09:39 AM

use a layer mask!

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

68 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

Related Questions

When I run getPixel32 () in WebcamTexture, only black pixels are returned. 1 Answer

Change Texture2D readable flag at runtime (or at least a workaround to do that) 0 Answers

RenderTexture to Texture2D very slowly 0 Answers

Memory Leaks when play pictures from local card using Sprite.Create 1 Answer

2D Sprite.Create isn't working 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