- Home /
Capture Screenshot then add resulting .png to an array
Hi, I have a function that takes a screenshot of the main camera's view. These screens are then saved to a folder in the root of my project. I was wondering how I would then take that screenshot, add it to a variable in code and add that to an array so I can call the image up and display it on screen. I have the display part sorted but I'm not sure how to access the file and add it to the array. I'm using Application.CaptureScreenshot, any help would be appreciated :)
Answer by robertbu · Nov 27, 2013 at 04:17 PM
The easiest way to solve your problem is to use Unity's WWW class to load the file. You just specify a local file. Typically using the WWW class, your code yields, but given the load of a local file you may be able to get away with polling the 'isDone' flag. It depends on the number of images and load times of each image:
#pragma strict
var path = "file://e:/AngleAxis.jpg";
function Update () {
if (Input.GetKeyDown(KeyCode.Space)) {
renderer.material.mainTexture = LoadImage(path);
}
}
function LoadImage(name : String) : Texture {
var www = new WWW(path);
while (!www.isDone);
return www.texture;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613122926im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can you help me with my loading screen 0 Answers
JS-Complicated Directory Array Texture Method 0 Answers
Textures making 1 Answer
Showing Texture Arrays in The Inspector 2 Answers