本文告诉大家如何在 UWP 从 文件 StorageFile 转 SoftwareBitmap 图片的方法 使用以下三步即可从文件 StorageFile 转 SoftwareBitmap 图片 第一步是读取文件 decoder.GetSoftwareBitmapAsync(); 我封装的代码如下 private static async Task<SoftwareBitmap> StorageFileToSoftwareBitmapAsync(StorageFile
本文主要:获取文件大小 private async Task<ulong> FileSize(Windows.Storage.StorageFile file) { var
领8888元新春采购礼包,抢爆款2核2G云服务器95元/年起,个人开发者加享折上折
{ StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await StorageFile.GetFileFromPathAsync(folder.Path + "\\" + str); } catch false; var allfiles = await ApplicationData.Current.LocalFolder.GetFilesAsync(); foreach (var storageFile in allfiles) { if (storageFile.Name == fileName) { fileExists = true ; } } return fileExists; } 如果我有很多文件,那么这样也是不好 我们有比较好的方法 StorageFile file;
class MainPage : PhoneApplicationPage { //为程序获取一个虚拟的本地存储 IsolatedStorageFile storageFile storageFile.DirectoryExists(filePath)) { storageFile.CreateDirectory(filePath ); } //写入 using (StreamWriter writer = new StreamWriter(storageFile.OpenFile storageFile.FileExists(fullFilePath)) { txbReadContent.Text = "指定文件不存在" return; } //读取 using (StreamReader reader = new StreamReader(storageFile.OpenFile
"image"; StorageFolder folder = await _folder.GetFolderAsync(str); StorageFile { var filelist = await con.GetStorageItemsAsync(); foreach (StorageFile in filelist) { } } IStorageItem 转 StorageFile if (t.IsOfType(StorageItemTypes.File)) { StorageFile storageFile = storageItem as StorageFile; } 在以前的软件,可以用过剪贴板获得任意内容,而uwp只能获得有限的内容
, jobId, blobKey, storageFile, LOG, blobKey instanceof PermanentBlobKey ? ", blobKey, jobId); } storageFile = null; } finally { // storageFile.delete() && storageFile.exists()) { log.warn("Could not delete the storage ", storageFile); } if (incomingFile != null && ! ,如果blobStore不为null,还会将storageFile放入到BlobStore doc BlobWriter
imageQuality 就是图片质量,这个需要传入 从一个图片文件压缩图片大小的方法可以这样写,创建一个方法传入原图文件,和需要输出的文件,和图片质量 private async Task<StorageFile > ConvertImageToJpegAsync(StorageFile sourceFile, StorageFile outputFile, double imageQuality 到 1 其中 1 的质量最好,这个值设置只对 jpg 图片有效</param> /// <returns></returns> private async Task<StorageFile > ConvertImageToJpegAsync(StorageFile sourceFile, StorageFile outputFile, double imageQuality
] { "001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg"}; foreach (var image in images) { var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(string.Format("ms-appx:///Assets/airplane /{0}", image), UriKind.RelativeOrAbsolute)); using (var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read new List<string>() { airplaneTag.Id.ToString() }); } } foreach (var image in images) { var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(string.Format("ms-appx:///Assets/alarmclock
让用户选择文件保存的位置,我们需要用FileSavePicker,它会返回一个StorageFile对象,表示我们要保存的照片文件。你也可以选择文件格式,我这里选择照片最常用的JPG格式。 savePicker.FileTypeChoices.Add("Jpg Image", new[] { ".jpg" }); savePicker.SuggestedFileName = "example.jpg"; StorageFile 最后一步,把SoftwareBitmap保存到StorageFile的代码如下 private static async Task<FileUpdateStatus> WriteToStorageFile (SoftwareBitmap bitmap, StorageFile file) { StorageFile sFile = file; if (sFile !
= null) { // open the file StorageFile textfile = await storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx: ///Assets/task.json")); await storageFile.CopyAsync(ApplicationData.Current.LocalFolder ); json = await FileIO.ReadTextAsync(storageFile); } return { StorageFolder localfolder = ApplicationData.Current.LocalFolder; StorageFile
WriteableBitmap 到文件 private static async Task SaveWriteableBitmapImageFile(WriteableBitmap image, StorageFile } 从文件读 WriteableBitmap private static async Task<WriteableBitmap> OpenWriteableBitmapFile(StorageFile ToBase64(bytes, (uint)bitmap.PixelWidth, (uint)bitmap.PixelHeight); } private async Task<string> ToBase64(StorageFile //codepaste.net/ijx28i 从文件读 BitmapImage private async Task<BitmapImage> OpenBitmapImageFile(StorageFile 我的图片从解决方案获得,大家可以从任意的位置获取,只要可以转换为 IRandomAccessStream var file = await StorageFile.GetFileFromApplicationUriAsync
return temp; } 存放文件 string image = Md5(uri.AbsolutePath); StorageFile ConvertIRandomAccessStreamByte(stream)); 从本地打开 把Uri转为图片名,打开本地文件 string name = Md5(uri.AbsolutePath); StorageFile string name = Md5(uri.AbsolutePath); try { StorageFile string image = Md5(uri.AbsolutePath); try { StorageFile
openPicker = new FileOpenPicker(); openPicker.FileTypeFilter.Add(".mp4"); StorageFile openPicker = new FileOpenPicker(); openPicker.FileTypeFilter.Add(".mp4"); StorageFile Image.Source = bitmapImage; public async Task<IInputStream> GetThumbnailAsync(StorageFile flyout.ShowAt(slider); } private async Task<IInputStream> GetThumbnailAsync(StorageFile
我在 Assets 放了图片 1.jpg 那么我要把他拿出来可以 <Image Source="ms-appx:///Assets/logo.png" /> var file=await StorageFile.GetFileFromApplicationUriAsync local ,临时文件 temp 等,可以使用 ms-appdate:// 后面加/ local、temp 如果我们本地有 1.png 放在 local 我们可以使用 var file=await StorageFile.GetFileFromApplicationUriAsync
,图片宽度,有设置上传为设置宽度 Height 默认-1,图片高度 public abstract void UploadImage() 上传图片,不同的类可以有不同上传 我们类需要传StorageFile 我们上传的是我们的StorageFile,上传完可以有ResponseInfo private async Task UploadImage(UploadImageTask uploadImageTask
扫码关注腾讯云开发者
领取腾讯云代金券