Application.Capturescreenshot(fileName) save to specific path - unity3d

i am using in my unity project this method that saves the camera viewport to the file system:
Application.Capturescreenshot(fileName)
it is work great but i want it to be saved under a specific path.
for example : Application.Capturescreenshot(c:/screenshots/filename);
how can i managed this?
thnaks!

You could use the absolute file path easily by passing it as a string. In your case, using this statement should work just fine:
Application.CaptureScreenshot("C:/screenshots/filename");
Note that it will give you an error if screeshots folder does not exist. Hence, if you are uncertain of that, you could modify the code accordingly:
// File path
string folderPath = "C:/screenshots/";
string fileName = "filename";
// Create the folder beforehand if not exists
if(!System.IO.Directory.Exists(folderPath))
System.IO.Directory.CreateDirectory(folderPath);
// Capture and store the screenshot
Application.CaptureScreenshot(folderPath + fileName);
Lastly, if you want to use a relative path instead of an absolute one, Unity provides dataPath and persistentDataPath variables to access the data folder path of the project. So, if you want to store the screenshots inside the data folder, you could change the folderPath above accordingly:
string folderPath = Application.dataPath + "/screenshots/";

var nameScreenshot = "Screenshot_" + DateTime.Now.ToString("dd-mm-yyyy-hh-mm-ss") + ".png";
ScreenCapture.CaptureScreenshot(nameScreenshot);
Try this !

Related

Flutter File.toString without 'File:...' to share image

Trying to get the file path to a string to share but when I print it is starting with 'File: ...'
Is there another method besides toString that I should be using to get the same path without these characters?
List<String> sharableFile = List<String>();
void shareFile() {
print(path.basename(photos[0].name.toString()))
print(photos[0].name.toString());
sharableFile.add(photos[0].name.toString());
Share.shareFiles(sharableFile);
}
output of the two print statements are:
flutter: IMG_0005.JPG'
flutter: File: '/Users/firstlast/Library/Developer/CoreSimulator/Devices/9A654C10-BD7B-4D39-8BDB-A47E8D0C1AF6/data/Media/DCIM/100APPLE/IMG_0005.JPG'
If you want the File's path, just use its path property instead of calling toString() on it.
Note that if you want an absolute path, you might need to use use the absolute property to get an absolute version of the File object first.

Iterating and reading text files from folder on Android

I made a word game app for android in Unity, where the player has to find a word from a category previously loaded to the game.
The way I load the categories is:
There is a folder named Categories, inside Assets, I run through the folder and read each text file as a category.
The categories are stored in a dictionary where the key is name the of the file and the value is every line of the file as an array element.
It worked well on the PC however no luck on android. Tried changing the path to
"public string categoriesDirectoryPath = Application.persistentDataPath +"Categories";" still does not work.
Original path was "Assets/Categories"
Code for initiating the dictionary with the file values is (Happens on GameManager's Awake()):
private Dictionary<string, string[]> createCategories(string directoryPath)
{
Dictionary<string, string[]> categories = new Dictionary<string, string[]>();
string[] categoryPaths = Directory.GetFiles(directoryPath);
foreach (string path in categoryPaths)
{
if (!path.EndsWith("meta")) {
Debug.Log(path);
string categoryName = Path.GetFileNameWithoutExtension(path);
Debug.Log(categoryName);
string[] categoryData = File.ReadAllLines(path).ToArray();
categories.Add(categoryName, categoryData);
}
}
return categories;
}
Is there a way of iterating the folder and reading the text files that were in Assets/Categories after building the APK?
Is there a way of iterating the folder and reading the text files that
were in Assets/Categories after building the APK?
No.
If you want to access from the project, in a build, you have two options:
1.Put the file a folder named "Resources" then use the Resources to read the file and copy it to the Application.persistentDataPath path. By copying it to Application.persistentDataPath, you'll be able to modify it. Anything in the "Resources" is read only.
2.Put the file in the StreamingAssets folder then use UnityWebRequest, WWW or the System.IO.File API to read it. Atfer this, you can copy it to the Application.persistentDataPath.
Here is a post with code examples on how to do both of these.
3.AssetBundle(Recommended due to performance and loading reaons).
You can build the file as AssetBundle then put them in the StreamingAssets folder and use the AssetBundle API to read it.
Here is a complete example for building and reading AssetBundle data.

How to load asset with same name, but placed in different folders from assetbundle?

I am using unity5.3.3, I would like to know how should I get the asset from an asset bundle, whose names are same but are kept in different folder. My AssetBundle Folder is set in the following manner:
MyAssets -> this Folder is packed as an AssetBundle
-ThemeOne(folder)
- Logo.png
-ThemerTwo(folder)
- Logo.Png
When I do AssetBundle.LoadAssetAsync("Logo"). I end getting the logo in the first(ThemeOne) folder. So how do I access the file in the other folder?
I have just created a sample project so that you can check it out. Check the Folder Assets\AssetBundleSample\SampleAssets\Theme and the script LoadAssets
You can put the ThemeOne(folder) and ThemeTwo(folder) in Resources Folder under assets and than use something like this
(AudioClip)(Resources.Load ("Sounds/" + "myaudioclip", typeof(AudioClip)) as AudioClip)
similarly load your png giving folder name first as i have given sounds and than name of file as i have given myaudioclip .
cast as texture or something as you want
As unity official docs provided
public string BundleURL;
public string AssetName;
IEnumerator Start() {
// Download the file from the URL. It will not be saved in the Cache
using (WWW www = new WWW(BundleURL)) {
yield return www;
if (www.error != null)
throw new Exception("WWW download had an error:" + www.error);
AssetBundle bundle = www.assetBundle;
if (AssetName == "")
Instantiate(bundle.mainAsset);
else
Instantiate(bundle.LoadAsset(AssetName));
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);
} // memory is freed from the web stream (www.Dispose() gets called implicitly)
}
BundleURL will use the path where your actual assets is located. You can also use Application.dataPath in conjunction with ur specified path string.
Seems to be a bug. Still present in Unity version 5.3.3.
See: http://answers.unity3d.com/questions/1083400/asset-bundle-cant-have-multiple-files-with-the-sam.html
I'm not really sure if this is possible, you should read Explicit naming of assets which is FYI obsolete as on Unity 5.6. This allows you to explicitly name assets that you are including in the bundle. Alternatively, you could try,
bundle.LoadAsset("/Assets/ThemerTwo/Logo.png")
But generally, this is a bad practice to have assets of the same naming in the same bundle.
You can use the method LoadAssetAtPath() to specify the full path instead of just the asset name.
Example:
LoadAssetAtPath("Assets/Texture/Logo.jpg", typeof(Texture2D));
Documentation here: http://docs.unity3d.com/ScriptReference/AssetDatabase.LoadAssetAtPath.html

Images upload form laravel

My image upload doesn't work:
Controller:
if (Input::hasFile('image')) {
$bikecreate->image = Input::file('image');
$destinationPath = public_path().'/upload/';
$filename = str_random(6) . '_' . $bikecreate->users_id ;
Input::file('image')->move($destinationPath, $filename);
}
Form:
{{ Form::file('image', array('files' => true)) }}
After accepting form everything looks ok, but after the end of upload, filepath in database show .tmp/file at my server.
Without seeing the rest of your code it's hard to see exactly what's going on but my guess is that your line $bikecreate->image = Input::file('image') is where you're setting the file's path for the database. You've actually set the UploadedFile instance as the image property on $bikecreate there, which, presumably, when serialised to something to put into the database gets __toString() called on it.
__toString() called on a File instance (which itself inherits __toString from SPLFileInfo returns the path to that file. So you'd think you're get the uploaded filename, but actually because an uploaded file is actually a temporary file in PHP, you get the temporary name.
Try changing that line to the following:
$bikecreate->image = Input::file('image')->getClientOriginalName();
This retrieves the actual original name of the uploaded file, not the temporary path given to it by PHP.
It goes without saying that this is only pertinent to UploadedFiles, normal files should just be able to be __toStringed to get the path to the file, although you'll notice that it would be the full path and not the basename. To get that, use getBaseName().

Mirth: How to get source file directory from file reader channel

I have a file reader channel picking up an xml document. By default, a file reader channel populates the 'originalFilename' in the channel map, which ony gives me the name of the file, not the full path. Is there any way to get the full path, withouth having to hard code something?
You can get any of the Source reader properties like this:
var sourceFolder = Packages.com.mirth.connect.server.controllers.ChannelController.getInstance().getDeployedChannelById(channelId).getSourceConnector().getProperties().getProperty('host');
I put it up in the Mirth forums with a list of the other properties you can access
http://www.mirthcorp.com/community/forums/showthread.php?t=2210
You could put the directory in a channel deploy script:
globalChannelMap.put("pickupDirectory", "/Mirth/inbox");
then use that map in both your source connector:
${pickupDirectory}
and in another channel script:
function getFileLastModified(fileName) {
var directory = globalChannelMap.get("pickupDirectory").toString();
var fullPath = directory + "/" + fileName;
var file = Packages.java.io.File(fullPath);
var formatter = new Packages.java.text.SimpleDateFormat("yyyyMMddhhmmss");
formatter.setTimeZone(Packages.java.util.TimeZone.getTimeZone("UTC"));
return formatter.format(file.lastModified());
};
Unfortunately, there is no variable or method for retrieving the file's full path. Of course, you probably already know the path, since you would have had to provide it in the Directory field. I experimented with using the preprocessor to store the path in a channel variable, but the Directory field is unable to reference variables. Thus, you're stuck having to hard code the full path everywhere you need it.