Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by Avisingh · Mar 03, 2014 at 11:37 AM · c#androidtexture2druntimeplane

Can not retrive image form device to the plane at runtime.

Hi.... Below is my code. i was successful in saving an image but can not retrieve back and apply to the plane. Please help??

using UnityEngine; using System.Collections;

public class LoadTexture : MonoBehaviour {

 public string deviceName;
 WebCamTexture wct;
 public static string path = "";
 private Texture2D m_Texture;
 public static bool TakePic;
 public GameObject PlaneObjet;
 bool isplaneactive = false;
 // Use this for initialization
 static string imagename;

 void Start () 
 {
     WebCamDevice[] devices = WebCamTexture.devices;
     deviceName = devices[0].name;
     wct = new WebCamTexture(deviceName,1280,800,30);
     renderer.material.mainTexture = wct;
     wct.Play();
     TakePic = false;
     imagename ="img.png";
 }
 void OnGUI()
 {
     if (GUI.Button(new Rect(10,10,100,30), "Click"))
     {
         Application.CaptureScreenshot(imagename);
         path = Application.persistentDataPath;
         isplaneactive = true;
         GUI.Label(new Rect(0,0,200,50), path);
     }

     if(isplaneactive)
     {
         if(GUI.Button(new Rect(0,0,100,100), "Paste"))
         {
             this.gameObject.SetActive(false);
             PlaneObjet.SetActive(true);
             Pasteimage();

         }
     }
 }

 IEnumerator TakeScreenshotAndLoadItIntoTexture(string filename) 
 {
     //Application.CaptureScreenshot(filename);
     WWW www = new WWW(filename);
     GUI.Label(new Rect(0,0,200,50), "image path = "+path);
     Debug.Log ( filename );
     Debug.Log (www.error.ToString() );
     yield return www;
     Texture2D texTmp = new Texture2D(1024, 1024, TextureFormat.DXT1, false);  
     www.LoadImageIntoTexture(texTmp);


     m_Texture = texTmp;
     
     PlaneObjet.renderer.material.SetTexture("_MainTex", m_Texture);
 }
 // Use this for initialization
 void Pasteimage()
 {
     //StartCoroutine(WaitForRequest(www));
     path = path+"/"+imagename;
     TakeScreenshotAndLoadItIntoTexture(path);
 }

}

image is saved but not able to apply on plane......... any advices?? can i know where i'm doing wrong??

Comment
Add comment · Show 2
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 robertbu · Mar 03, 2014 at 12:52 PM 1
Share

If you are just trying to capture the screenshot to use in the game (i.e. you don't need the image on disk), you can use ReadPixels() ins$$anonymous$$d:

http://answers.unity3d.com/questions/649079/how-to-get-a-screenshot-in-game.html

avatar image ArkaneX · Mar 04, 2014 at 12:23 PM 0
Share
  • for robertbu's comment. But if you need to save image locally, then:

    • TakeScreenshotAndLoadItIntoTexture is a coroutine, but you call it as a normal method (i.e. without StartCoroutine)

    • you should log www.error after yield

    • AFAI$$anonymous$$ loading local file using www requires file:// prefix in path

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Should I load all the database items on my android device? 1 Answer

How to use native android file-open-dialog in Unity? 1 Answer

Add BoxCollider2d and Rigidbody2D with script 0 Answers

Multiple Cars not working 1 Answer

confusion with sprites. 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