- Home /
Solved by own
Show Screenshot in display.
Hi world, am currently working an augmented reality project which have to take a screenshot and upload facility. I have done a screenshot script and save into custom path that's all working perfectly(but can't see into gallery another issue). Now when i took a screenshot its saved but i want to display suddenly onto my screen. This is my code for taking screenshot and save into the folder.
using UnityEngine;
using System.Collections;
public class Capture : MonoBehaviour
{
// Store more screenshots...
private int Screen_Shot_Count = 0;
// Screenshot taking by touch the button.
public GUITexture Capture_Model;
// Check the Shot Taken/Not.
private bool Shot_Taken = false;
// Name of the File.
private string Screen_Shot_File_Name;
void Update()
{
if (Input.touches.Length > 0)
// Finger hit the button position.
if(Capture_Model.HitTest (Input.GetTouch(0).position))
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
// Increament the screenshot count.
Screen_Shot_Count++;
// Save the screenshot name as Screenshot_1.png, Screenshot_2.png, with date format...
Screen_Shot_File_Name = "Screenshot__" + Screen_Shot_Count + System.DateTime.Now.ToString("__yyyy-MM-dd") + ".png";
Application.CaptureScreenshot(Screen_Shot_File_Name);
Shot_Taken = true;
}
}
if(Shot_Taken == true)
{
string Origin_Path = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
// This is the path of my folder.
string Path = "/mnt/sdcard/DCIM/Inde/" + Screen_Shot_File_Name;
if(System.IO.File.Exists(Origin_Path))
{
System.IO.File.Move(Origin_Path, Path);
Shot_Taken = false;
}
}
}
}
Now i want to solve this two problems.
Display the screenshot once it taken.
I can view the screenshot from gallery folder.
Answer by Prasanna · Dec 11, 2014 at 12:15 PM
Finally found another way.
using UnityEngine;
using System.Collections;
public class Capture : MonoBehaviour
{
// Store more screenshots...
private int Screen_Shot_Count = 0;
// Screenshot taking by touch the button.
public GUITexture Capture_Model;
public GUITexture Show_Screen;
public GUITexture Close_Screen;
// Check the Shot Taken/Not.
private bool Shot_Taken = false;
// Name of the File.
private string Screen_Shot_File_Name, Path_Name;
private string File_Path, Origin_Path;
private byte[] Bytes_File;
private Texture2D Screenshot;
void Update()
{
if (Input.touches.Length > 0)
// Finger hit the button position.
if(Capture_Model.HitTest (Input.GetTouch(0).position))
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
// Increament the screenshot count.
Screen_Shot_Count++;
// Save the screenshot name as Screenshot_1.png, Screenshot_2.png, with date format...
Screen_Shot_File_Name = "Screenshot__" + Screen_Shot_Count + System.DateTime.Now.ToString("__yyyy-MM-dd") + ".png";
Application.CaptureScreenshot(Screen_Shot_File_Name);
}
}
if(Close_Screen.HitTest (Input.GetTouch(0).position))
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
Screenshot = null;
Shot_Taken = true;
}
}
if(Shot_Taken == true)
{
Origin_Path = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
// This is the path of my folder.
File_Path = "/mnt/sdcard/DCIM/Inde/" + Screen_Shot_File_Name;
if(System.IO.File.Exists(Origin_Path))
{
System.IO.File.Move(Origin_Path, File_Path);
Shot_Taken = false;
}
}
}
void OnGUI()
{
if (Input.touches.Length > 0)
// Finger hit the button position.
if(Show_Screen.HitTest (Input.GetTouch(0).position))
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
Path_Name = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
Bytes_File = System.IO.File.ReadAllBytes(Path_Name);
Screenshot = new Texture2D(0, 0, TextureFormat.ATF_RGB_DXT1, false);
Screenshot.LoadImage(Bytes_File);
}
}
if(Screenshot != null)
{
GUI.DrawTexture(new Rect(Screen.width/2 - 200, Screen.height/2 - 150, 400, 300), Screenshot);
}
}
}
that I think is android specific question already. do you see the folder 'Inde' in your file browser?
Yes, i saw the folder. Because i created the folder not through scripts once i create a folder through script, my save path is not working.
mm... I don't know, THIS post says unity does not have permission for writing outside its data folders :/ it's weird you actually can view your screenshot.
That's condition only for application.datapath not in application.persistantdatapath. We can create a path using application.persistantdatapath, now am trying to finding the way to create a runtime folder and make that as a path.
Answer by taxvi · Dec 11, 2014 at 07:54 AM
have a look at WWW.LoadImageIntoTexture docs
Is this work with android? because currently am working android device.
should work, it's working on iOS. I'm storing a my files in my app's temp folder and have no problems.
Thanks for your help, if i have any doubt let me ask you.
if the path is the local disk of the device it should be of a format "file:///homedir/someOtherDir/.../appDir/yourDir" make sure you have the "file:///" in the beginning of the url
Follow this Question
Related Questions
Load the sprite property of a png file from Application.persistentDataPath 2 Answers
capture the screenshot to iPhone photo gallery 2 Answers
I need to take a screenshot from a FLASH BUILD 1 Answer
I need to set the path for saving the pictures with an application for Android and IOS 2 Answers
File.Delete problems with Application.CaptureScreenshot 2 Answers