- Home /
How to show image on Camera View programmatically in Unity3d
I am working in app, using Vuforia Library in which i am using camera(device camera). I want to render 2d Texture(any .png or .jpg) on camera defined its coordinate and its size. I tried but my app always getting crash. I don't know whats wrong i am doing. Please help me on That this will be great for me.
string tempPath = "/Assets/Images/119642-samsung-galaxy-note-2-picture-large.jpg";
Texture2D tex = new Texture2D(400,350); Resources.LoadAssetAtPath(tempPath, typeof(Texture2D)); renderer.material.mainTexture = tex as Texture2D;
Here above is what i am doing. Thanks in advance.
Answer by Psymon · Jan 02, 2013 at 05:00 PM
Resources.LoadAssetAtPath is only available in an editor script.
You need to put your picture in a Resources/ folder and then load it with Resources.Load without the extension.
Ex : 119642-samsung-galaxy-note-2-picture-large.jpg is in Assets/Resources/ folder.
Texture2D tex = Resources.Load("119642-samsung-galaxy-note-2-picture-large") as Texture2D;
renderer.material.mainTexture = tex;
In my project there is no Resources Folder, so then i created new folder with same name "Resources" and drag this image onto "Resources" folder, and run your code but still crashing:(. Its crash on renderer.material.mainTexture = tex; line
What is the error ? Is the script attached to a gameObject which have a renderer and a material ? Also after the Resources.Load write : Debug.Log(tex); And check if the Log returns a texture2D. If it's return nothing then your image is not loaded.
Thanks. It worked but what i need I want to show Image which is stuck at some where point not with camera. I am building a GPS base App and i want to show image at specific building when user move camera toward that building and that image looks like stuck with that building not with camera, like I am showing now.
Sorry I can't help you on this one because I never tried to access to the camera device :(
Your answer
Follow this Question
Related Questions
GetPixel in c# 1 Answer
How to set image in Aspect fit on Texture2D 0 Answers
Interactive Textures? 1 Answer
How is this effect achieved (newbie question)? 1 Answer
Cloud recognition in Vuforia 0 Answers