public async void LoadImageAsync(string imageName) { string imagePath = string.Format("ms-appx:///Icons/{0}", imageName); var uri = new System.Uri(imagePath); var file = await StorageFile.GetFileFromApplicationUriAsync(uri); BitmapImage bitmapImage = new BitmapImage(); Windows.Storage.Streams.FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); ImageSource = bitmapImage; }
/// <summary> /// Uploads a image file to imgur. /// </summary> /// <param name="baconMan"></param> /// <param name="image"></param> /// <returns></returns> public static string UploadImageToImgur(BaconManager baconMan, FileRandomAccessStream imageStream) { //try //{ // // Make the data // List<KeyValuePair<string, string>> data = new List<KeyValuePair<string, string>>(); // data.Add(new KeyValuePair<string, string>("key", "1a507266cc9ac194b56e2700a67185e4")); // data.Add(new KeyValuePair<string, string>("title", "1a507266cc9ac194b56e2700a67185e4")); // // Read the image from the stream and base64 encode it. // Stream str = imageStream.AsStream(); // byte[] imageData = new byte[str.Length]; // await str.ReadAsync(imageData, 0, (int)str.Length); // data.Add(new KeyValuePair<string, string>("image", WebUtility.UrlEncode(Convert.ToBase64String(imageData)))); // string repsonse = await baconMan.NetworkMan.MakePostRequest("https://api.imgur.com/2/upload.json", data); //} //catch (Exception e) //{ // baconMan.TelemetryMan.ReportUnExpectedEvent("MisHelper", "failed to submit post", e); // baconMan.MessageMan.DebugDia("failed to submit post", e); // return new SubmitNewPostResponse() { Success = false }; //} throw new NotImplementedException("This function isn't complete!"); }
public FileStream(string file, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) { try { this.fileOptions = options; this.name = file; this.CheckAccess(mode, access); StorageFile storageFile; switch (mode) { case FileMode.CreateNew: case FileMode.Create: case FileMode.OpenOrCreate: case FileMode.Append: storageFile = FileStream.CreateFile(file, mode, access); break; case FileMode.Open: case FileMode.Truncate: storageFile = FileStream.OpenFile(file, mode, access); break; default: throw new ArgumentException("Unknown file mode"); } IAsyncOperation<IRandomAccessStream> source = storageFile.OpenAsync(FileStream.GetAccessMode(access)); WindowsRuntimeSystemExtensions.AsTask<IRandomAccessStream>(source).Wait(); this.backend = (FileRandomAccessStream)source.GetResults(); if (mode == FileMode.Truncate) { this.backend.Size = 0UL; } else { if (mode != FileMode.Append) return; this.backend.Seek(this.backend.Size); } } catch (Exception ex) { throw FileStream.RethrowException(ex); } }