• 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 /
avatar image
1
Question by Abirami-Govindarajan · Jul 07, 2017 at 05:02 PM · transparentoverlayopencv

how to overlay transparent png image?

I'm trying to overlay a transparent png over original image(Lena.jpg). I used addWeighted function to blend. It didn't give me a good result. Is there any other way to overlay two images. My desirable output is spectacles visible with transparent rectangular region on Lena image. Kindly Help. alt text

texturetomatdisplay.png (431.4 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by toddisarockstar · Jul 07, 2017 at 09:17 PM

first of all you need go to the import settings of your images. select Advanced for a texture type. then check the box to make them readable. here is a quick script i wrote to give you the idea. this should work if the second image is not bigger than the first. resizing is another question!

 public Texture2D img1;// start texture
 public Texture2D img2;// overlay this over top  
 public Texture2D result;
 Color col;
 float alph;
 void Start () {
 
         int x = img2.width;
         int y = img2.height;
         result = new Texture2D (x,y);
         // loop through your pixels
         while(x>0){x--;
             y=img2.height;
         while(y>0){y--;
                 //use the alpha channel of 2nd image to mix the colors
                 alph = img2.GetPixel(x,y).a;

                              // remove this next line if you don't want alpha cutoff!
                             if(alph>.5f){alph=1f;}else{alph=0;}

                 col= img2.GetPixel(x,y);
                 col= col*alph;
                 alph=1f-alph;
                 col=col+img1.GetPixel(x,y)*alph;
                 result.SetPixel(x,y,col);
 }}
         result.Apply ();
     }

of course you could alteratively write a similar custom shader script.

Comment
Add comment · Show 1 · 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
avatar image Abirami-Govindarajan · Jul 12, 2017 at 07:14 AM 0
Share

@toddisarockstar Thank you for helping me out.

avatar image
0

Answer by jethrogillgren · May 02, 2018 at 12:04 PM

If you just want a png with transparency to sit on top of another image, you can do it without code.

Tick "Alpha is transparency" on the image, and setting the Material shader to Cutout (standard in cutout mode, or "Unlit/Transparent Cutout"). Add planes with each image, and make sure the glasses one is in front of the person.

See: https://lmhpoly.com/unity-tutorial-how-to-create-transparent-texture/

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

69 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

Related Questions

Key out / Remove a color in a specific area 0 Answers

GUI.DrawTexture - Slightly Transparent? 1 Answer

Transparent game objects 4 Answers

Opaque specular on transparent object? (i.e. glass sphere) 0 Answers

water transparent 1 Answer


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