public async Task <SoftwareBitmap> readImageFile(string uri) { KeyValuePair <string, string> PathNamePair = WebManager.convertPathFilenameFromUri(uri); StorageFolder storageFolder = await ApplicationData.Current.LocalFolder .CreateFolderAsync(PathNamePair.Key, CreationCollisionOption.OpenIfExists); StorageFile storageFile = await storageFolder.GetFileAsync(PathNamePair.Value); using (var stream = await storageFile.OpenAsync(FileAccessMode.Read)) { if (stream.Size == 0) // Иногда картинки криво сохраняются и совершенно не собираются читаться { return(null); } BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); // Тут этот гад кидает System.Exception при нулевом размере файла SoftwareBitmap resultBitmap = await decoder.GetSoftwareBitmapAsync(); resultBitmap = SoftwareBitmap.Convert(resultBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore); return(resultBitmap); } }
public async Task <bool> isFileActual(string uri) { KeyValuePair <string, string> PathNamePair = WebManager.convertPathFilenameFromUri(uri); StorageFolder storageFolder = await ApplicationData.Current.LocalFolder .CreateFolderAsync(PathNamePair.Key, CreationCollisionOption.OpenIfExists); if (await storageFolder.TryGetItemAsync(PathNamePair.Value) == null) { return(false); } else { return(true); } }
public async Task <bool> createImageFile(string uri, SoftwareBitmap image) { KeyValuePair <string, string> PathNamePair = WebManager.convertPathFilenameFromUri(uri); StorageFolder storageFolder = await ApplicationData.Current.LocalFolder .CreateFolderAsync(PathNamePair.Key, CreationCollisionOption.OpenIfExists); StorageFile storageFile = await storageFolder .CreateFileAsync(PathNamePair.Value, CreationCollisionOption.ReplaceExisting); using (var stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite)) { BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream); encoder.SetSoftwareBitmap(image); await encoder.FlushAsync(); } return(true); }