On C#, raspberry, windows IOT,
The app stop on this line
StorageFile file = await storageFolder.GetFileAsync("Signature.jpg",
CreationCollisionOption.ReplaceExisting);
I get this error :
an item cannot be found at the specified path
But Signature.jpg is on this folder existing
Thanks for your help,
I can also reproduce this issue when access the shared file on a computer from Windows 10 IoT core.
The workaround for this issue is that you can setup a web server to share the file instead of using file sharing. For example, I setup the IIS on my computer and copy the signature.jpg to the root folder of IIS(C:\inetpub\wwwroot). Then we can use the code below download the file from IIS:
async void DownloadImageAndDisplay()
{
Uri fileUri = new Uri("http://{AddressOfPC}/signature.jpg");
IRandomAccessStreamReference thumbnail =
RandomAccessStreamReference.CreateFromUri(fileUri);
StorageFile imageFile=await StorageFile.CreateStreamedFileFromUriAsync("signature.jpg", fileUri, thumbnail);
BitmapImage bitmapImage = new BitmapImage();
Windows.Storage.Streams.RandomAccessStreamOverStream stream = (Windows.Storage.Streams.RandomAccessStreamOverStream)await imageFile.OpenAsync(FileAccessMode.Read);
bitmapImage.SetSource(stream);
image.Source = bitmapImage;
}
Related
Does anyone know, how to download a Image from a path like "C:/Data/Users/Public/Pictures/Camera Roll/Picture.jpg" (in a Windows Phone 8.1 Device) and save it as a BitmapImage? I tried it with this, but after that I don't know, how to save the StorageFile as a BitmapImage.
StorageFolder picturesFolder = KnownFolders.CameraRoll;
StorageFile storageFile = await picturesFolder.GetFileAsync(fileName);
I hope someone can help me.
Cristian
Create a stream out of the file and open it via SetSourceAsync (here).
using (var stream = await storageFile.OpenReadAsync())
{
await bitmap.SetSourceAsync(stream);
}
I am writing a Windows store application that loads .png image from assets.
The code:
private static readonly string filePath = "ms-appx:///Base/Assets/Faces/img1.png";
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(filePath, UriKind.Absolute));
When I test application on computer, image loads correctly, but when I test it on a tablet, image doesn't load. For more information: image doesn't load on ARM processors, on x86 everything works.
Image property set to Copy always and Content.
Try calling the method without UriKind parameter:
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(filePath));
I'm building an app that needs to take a photo with webcam and save it to the local disk, so far I have this:
async private void CapturePhoto_Click(object sender, RoutedEventArgs e)
{
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
// create storage file in local app storage
StorageFile file = await localFolder.CreateFileAsync("TestPhoto.jpg", CreationCollisionOption.GenerateUniqueName);
StorageFile localFile = await localFolder.CreateFileAsync("webcamPhotoTest.jpg", CreationCollisionOption.ReplaceExisting);
// take photo
// save to app storage
await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file);
// save to local storage
await captureManager.CapturePhotoToStorageFileAsync(imgFormat, localFile);
// Get photo as a BitmapImage
BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));
// imagePreview is a <Image> object defined in XAML
imagePreview.Source = bmpImage;
}
I am able to save the jpg image both to app storage and local storage but I need to be able to
a) Specify the path to save to
b) do so without requiring user interaction (e.g windows save file prompt)
There are no support for System.Drawing in Windows 8 apps which complicates things. Most answers I've found have either been using System.Drawing features or windows' save file prompt.
You can't really use any location that you want. There is the list of locations that you can access from your app: File access and permissions in Windows Store apps. Some locations require additional declarations in the manifest file of your project.
My understanding is that when I set SL5 to run OOB and elevated trust that I should have wide open access to any directory/file on the local system. If an external system places png image files into the user's c:\images folder, how can I load the various png files into a XAML Image element?
This line works:
image.UriSource = new Uri(value as string);
if I set value to a string like "http://blah.com/image1.png"
But fails if I try to set it to:
ImageUrl = new Uri(#"C:\images\image3.png")
which gets resolved to something like "file:///C:....." when it hits the
image.UriSource = new Uri(value as string);
line.
How do I display png files in SL5 from any local path on the system running the OOB elevated app?
Something like this should work provided that you have elevated permissions set correctly
var bmp = new BitmapImage();
var stream = new FileStream(#"c:\dir\folder\image.png", FileMode.Open);
bmp.SetSource(stream);
stream.Close();
If you need to use a uri, this should work:
var bmp = new BitmapImage();
var uri = new Uri("c:/dir/folder/image.png");
bmp.UriSource = uri;
Note that the paths are different. The uri path requires forward slashes to be used.
You can then set the source of your image control to the bmp
image.Source = bmp;
If you're getting a 'File Operation not permitted' exception you need to double check that elevated permissions is checked in your out of browser settings
Project -> Properties -> 'Out of browser settings'
Check 'Require elevated trust...'
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));