- Home /
Image inventory
So I want something kind of complicated. I hope this makes sense:
I have a car game where I want a button that says "TAKE PICTURE" When you click the GUI button, the game will take a picture of the current camera view. it will also make a click sound (which i have)
Below that, there will be a GUI button that says "Pictures".
When you click that, all of the images that you have taken will show up in 4 columns.
you can scroll up and down this and when you click on one of the pictures, it will expand. when you click it again, it will go back.
If you quit the game and reopen it, the images will still be there.
There should also be a button that allows you to delete an image when you expand it that says "Delete Current Image"
I know this is a lot. Sorry!
Answer by flamy · Jan 02, 2012 at 06:24 AM
first thing first getting a texture from the camera can be done with the help of Render texture in unity.
After getting the screen shot you can use EncodeToPng function to get the byte data... You can save it as it is into the disk or u can again convert it into string64 using this function. Either way you would have to use System.IO classes to save it to disk, I suggest using StreamWriter class... similarly u can use streamReader for retriving the image back...When you press delete you can delete the file previously created....!! Hope it helpy :)
For tumb nail of the texture in the GUI you can use Graphics.DrawTexture. For expanding the image you can use the same function.
then go for some video tutorials... Unity is damn easy to start with compared to most other engines :)
Answer by KrisCadle · Feb 28, 2012 at 08:04 AM
This script lets you take screenshots and saves them next to your project, plus it draws a GUI texture of the last screenshot you took ;) Modify this for your own purpose. Add some animation and more GUI textures etc...
Put this on any object in your Hierarchy and drag any texture onto blankTexture. You can look at the "var url" in the inspector to see what file path is generated when you take a screenshot. This can be helpful for tweaking it...
private var count : int = 0; var blankTexture : Texture; var url = "";
function Update() { if(Input.GetKeyDown("s")) { ScreenshotEncode();
}
}
function ScreenshotEncode() {
yield WaitForEndOfFrame();
var texture:Texture2D = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(Rect(0.0, 0.0, Screen.width, Screen.height), 0.0, 0.0);
texture.Apply();
yield;
var encoder:JPGEncoder = new JPGEncoder(texture, 100.0);
while(!encoder.isDone)
yield;
File.WriteAllBytes(Application.dataPath + "Overwrite" + count + ".jpg", encoder.GetBytes());
Grab();
}
function Grab () {
url = ("file:" + Application.dataPath + "Overwrite" + count + ".jpg");
var www : WWW = new WWW (url);
yield www;
//you can also put this script on a cube and it will render the texture
//renderer.material.mainTexture = www.texture;
blankTexture = www.texture;
count = count+1;
}
function OnGUI() {
if(!blankTexture){
Debug.LogError("Assign a Texture in the inspector.");
return;
}
GUI.DrawTexture(Rect(10,200,360,260), blankTexture, ScaleMode.ScaleToFit, true, 1.0f);
}
If I export the game, how can i get this to work on another computer, (Say if I sent a web version to my friend or something, would it still work on their computer?) And I am also getting this error:
Assets/Image Capture Script.js(21,21): BCE0018: The name 'JPGEncoder' does not denote a valid type ('not found').
Your answer
Follow this Question
Related Questions
My unity image isn't showing up, what gives? 0 Answers
How to change button image on click 2 Answers
Why does my sprite turn invisible for the camera 1 Answer
Remove Items and Item Tooltips 0 Answers
Display a gameObject like a GUITexture 2 Answers