Basically I'm trying to make an UWP app to create Custom Tiles on Start Menu.
The SecondaryTile is working when the Tile Images are from Assets folder like this.
Uri square150x150Logo = new Uri("ms-appx:///Assets/square150x150Tile-sdk.png");
Uri wide310x150Logo = new Uri("ms-appx:///Assets/wide310x150Tile-sdk.png");
Uri square310x310Logo = new Uri("ms-appx:///Assets/square310x310Tile-sdk.png");
Uri square30x30Logo = new Uri("ms-appx:///Assets/square30x30Tile-sdk.png");
But I have images in ApplicationData folders and trying to use the path like this:
Uri square150x150Logo = new Uri(Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "ImageSquare.png"));
Uri wide310x150Logo = new Uri(Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "ImageWide.png"));
Uri square310x310Logo = new Uri(Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "ImageLarge.png"));
Uri square30x30Logo = new Uri(Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "ImageTiny.png"));
But this way the app is crashing. The debugger isn't working either. Any solutions?
To reference application data files, you should be using ms-appdata:///.
Calling TemporaryFolder.Path will return the absolute file path, C:\, which isn't allowed to be used on secondary tiles.
So your updated code would be...
Uri square150x150Logo = new Uri("ms-appdata:///temp/ImageSquare.png"));
OK finally figured it out.
In Addition to Andrew's answer, I had to change to using the LocalState folder instead of the TempState.
Andrew directed in the right way to use ms-appdata, but for some reason ms-appdata:///temp/ returned error. but using ms-appdata:///Local/ solved the Issue.
Related
sorry im very new to unity and c#.
Im trying to read an image and apply it as a texture.
The code works when i try it with an image on my computer, however, when i try it with my android devices (phone and AR glasses), i've not been able to specify the file path correctly. How do i specify the file path properly of android devices or is there a way i can get these file path?
Thank you so much for any help in advance! :)
void Start()
{
thisTexture = new Texture2D(100, 100);
//string path = "C:/Users/kenny/Desktop/5th March/im.png"; //this works
string path = "file:///storage/emulated/0/im2.png"; // this doesnt work
bytes = File.ReadAllBytes(path);
thisTexture.LoadImage(bytes);
GetComponent<Renderer>().material.mainTexture = thisTexture;
}
For mobile devices it is not as straightforward to get a file from a plain path.
One way of doing so is by using the Resources folder. In your root folder (Assets), create a new folder named Resources. Put your image there.
Then you can do something like this:
// path without file extension!
var texture = Resources.Load<Texture2D>("path/to/texture");
You can get more references for this functionality here: https://forum.unity.com/threads/how-to-load-a-image-from-the-resources-folder-to-a-texture2d.101542/
Alternatively, you could use the StreamingAssets folder, but that's another story.
I google a lot over this and still can't found a way to make it work
My app downloads epubs from many sources and then I save them to the local Storage (and unzip them)
I can read the extracted files with no problems with Storage commands but just can't to open it on WebView control
I tried all this:
The real path: C:\Data\Users\DefApps\APPDATA\Local\Packages\xxx\LocalState\***
Uri localUri = new Uri("ms-appx-web:///***/OEBPS/04_CL_CH.01.xhtml");
Uri localUri = new Uri("ms-appdata:///***/OEBPS/04_CL_CH.01.xhtml");
Uri localUri = new Uri("file:///***/OEBPS/04_CL_CH.01.xhtml");
Uri localUri = new Uri("file:///LocalState/***/OEBPS/04_CL_CH.01.xhtml");
Uri localUri = new Uri("file:///C://Data//Users//DefApps//APPDATA//Local//Packages//xxx//LocalState//***//OEBPS//04_CL_CH.01.xhtml");
// two ways
WebView1.Navigate(localUri);
WebView1.Source = localUri;
// this works, but as is an epub file, so need lot of files and styles
var XHTML = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("***\\OEBPS\\04_CL_CH.01.xhtml");
WebView1.NavigateToString(await Windows.Storage.FileIO.ReadTextAsync(XHTML));
This is a C# Windows Phone universal app, and I'm using VS 2013 Express
Take a look at http://blogs.windows.com/buildingapps/2013/07/17/whats-new-in-webview-in-windows-8-1/, it says:
ms-appdata:///local/TopLevelDirectory/file for files from the local
state
ms-appdata:///temp/TopLevelDirectory/file for files from the
app’s temporary state folder
How to get all files from a folder in XAML application using relative path?
I am playing with a Kinect application built in WPF. All images used in the application are in
[project dir]\Images\ and all backgrounds are in
[project dir]\Images\Backgrounds\.
I want to get list of all the images from Backgrounds directory using relative path. I have tried
DirectoryInfo(#"\Images\Backgrounds\").GetFiles();
but it says that Backgrounds directory must exist in [full path+project dir]\debug\bin\
Selecting each image manually works fine
Uri uri = new Uri(#"Images\Backgrounds\Background1.png", UriKind.Relative);
ImageSource imgsource = new BitmapImage(uri);
this.Backdrop.Source = imgsource;
It works for a single file because you specify URI to resource embedded in the assembly and not some folder on your drive, whilst GetFiles() will work only on a specific physical folder. So either you need to copy all your images instead of embedding them or use the code below and resourceNames should give you names of all resources that you can reference by URI in your project:
List<string> resourceNames = new List<string>();
var assembly = Assembly.GetExecutingAssembly();
var rm = new ResourceManager(assembly.GetName().Name + ".g", assembly);
try
{
var list = rm.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry item in list)
resourceNames.Add((string)item.Key);
}
finally
{
rm.ReleaseAllResources();
}
if you need then at this point each item.Value contains UnmanagedMemoryStream for each resource.
I would reply to your post instead of posting a solution, but I'm new to this site and dont have that privledge yet.... Hey! Just trying to help.
Anyway, I've had a problem similar to this before concerning DirectoryInfo. Can't remember exactly how I solved it, but I remember the backslashes being tricky. Have you checked out the MSDN site? It seems like it can't find your directory so its looking for it in debug by default. MSDN says the format should be "MyDir\MySubdir" in C#.
I am working on C# project i need to get the images from Images directory using relative path. I have tried
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + #"\Images\logo.png";
var logoImage = new LinkedResource(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)+#"\Images\logo.png")
But no luck with these...
I have made the images to be copied to output directory when the program is running but it doesn't pickup those images.
If you are using LinkedResource() in C# it is most likely not to pickup your relative URI or the file location.
You can use some extra piece of code
var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
var logoimage = Path.Combine(outPutDirectory, "Images\\logo.png");
string relLogo = new Uri(logoimage).LocalPath;
var logoImage = new LinkedResource(relLogo)
Now it will pickup your relative path, convert this to absolute path in memory and it will help you get the images.
First, add those image file to your project (create an Image folder is a good idea)
Second, select the image in your solution manager, and view the property window.
And then, change the "copy to output folder" to "always" or "copy when update".
PS. My IDE is Trad. Chinese so I can not ensure the correct keywords in your language.
I would make sure that the Images directory is in the output folder.
I usually use Assembly.GetExecutingAssembly().Location to get the location of my dll.
However, for images, I usually use the Resources page/collection in the project's Properties page. Here is more information about it. Putting the image in the project's Resource would automatically give you an easy way to access it.
For more information about GetExecutingAssembly: MSDN Page
if u want to display images in your folder using your application use an array and put all pictures in ur folder into array. then you can go forward and backward.
string[] _PicList = null;
int current = 0;
_PicList = System.IO.Directory.GetFiles("C:\\Documents and Settings\\Hasanka\\
Desktop\\deaktop21052012\\UPEKA","*.jpg");
// "*.jpg" will select all
//pictures in your folder
String str= _PicList[current];
DisplayPicture(str);
private void DisplayPicture(string str)
{
//throw new NotImplementedException();
BitmapImage bi = new BitmapImage(new Uri(str));
imagePicutre.Source = bi; // im using Image in WPF
//if u r using windows form application it must be a PictureBox i think.
label1.Content = str;
}
What's the best pattern to implement a local cache for a Metro Style App so that the images can be cached in the background while the app is being used on-line and to serve images when the App goes offline?
How do we set a BitmapSource to a local file upon discovering the lack of internet access? using new Uri(localpath, UriKind.Absolute) doesn't work.
Are the images already downloaded? If so, are they in the "Local" folder?
If so, you can build a BitmapImage from the path like this
var m_Image = new BitmapImage(new Uri("ms-appdata:///local/" + ImageFileName));
EDIT
If your file is stored in the package as a "never had access and can't download anything" standby, the Uri would be something like
var m_Image = new BitmapImage(new Uri("ms-appx:///Assets/" + FallBackImageFileName));