• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Storage.StorageFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Windows.Storage.StorageFile的典型用法代码示例。如果您正苦于以下问题:C# StorageFile类的具体用法?C# StorageFile怎么用?C# StorageFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StorageFile类属于Windows.Storage命名空间,在下文中一共展示了StorageFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: WriteDataToFileAsync

 public async Task WriteDataToFileAsync(StorageFile file, byte[] data)
 {
     using (var s = await file.OpenStreamForWriteAsync())
     {
         await s.WriteAsync(data, 0, data.Length);
     }
 }
开发者ID:tgptom,项目名称:aerogear-cordova-otp,代码行数:7,代码来源:Repository.cs


示例2: PictureCropControl

 public PictureCropControl(StorageFile file, AspectRatio aspect = AspectRatio.Custom, CropSelectionSize cropsize = CropSelectionSize.Half)
 {
     this.InitializeComponent();
     this.file = file;
     this.aspect = aspect;
     this.cropsize = cropsize;
 }
开发者ID:chenjianwp,项目名称:UWP_ToolKit_CommonLibrary,代码行数:7,代码来源:PictureCropControl.xaml.cs


示例3: Create

 public static async Task<WaveFile> Create(StorageFile file)
 {
     WaveFile w = new WaveFile();
     await w.Initialize(file);
     w.SmoothSamples(200);
     return w;
 }
开发者ID:david-wb,项目名称:Transcriber,代码行数:7,代码来源:WaveFile.cs


示例4: LoadAsync

 /// <summary>
 /// Loads the WriteableBitmap asynchronously given the storage file and the dimensions.
 /// </summary>
 /// <param name="storageFile">The storage file.</param>
 /// <param name="decodePixelWidth">Width in pixels of the decoded bitmap.</param>
 /// <param name="decodePixelHeight">Height in pixels of the decoded bitmap.</param>
 /// <returns></returns>
 public static async Task<WriteableBitmap> LoadAsync(
     StorageFile storageFile,
     uint decodePixelWidth,
     uint decodePixelHeight)
 {
     return await new WriteableBitmap(1, 1).LoadAsync(storageFile, decodePixelWidth, decodePixelHeight);
 }
开发者ID:siatwangmin,项目名称:WinRTXamlToolkit,代码行数:14,代码来源:WriteableBitmapLoadExtensions.cs


示例5: OpenCheckList

        //-------------------------------------------------------------------------------
        #region +OpenCheckList チェックリストを開く
        //-------------------------------------------------------------------------------
        //
        public async Task<bool> OpenCheckList(StorageFile file, Func<char, Task<int>> dayToDayIndexFunc, Func<int, Task<ComiketCircleAndLayout>> updateIdToCircle)
        {
            string enc_str = null;
            using (var str = await file.OpenReadAsync())
            using (StreamReader sr = new StreamReader(str.AsStreamForRead())) {
                string line = sr.ReadLine();
                enc_str = CheckList.CheckEncode(line);
                if (enc_str == null) { return false; }
                int comiketNo = CheckList.CheckComiketNo(line);
                if (comiketNo != _comiketNo) { return false; }
            }

            Encoding enc = Encoding.GetEncoding(enc_str);

            bool res;
            using (var str = await file.OpenReadAsync())
            using (StreamReader sr = new StreamReader(str.AsStreamForRead(), enc)) {
                var lines = CheckList.FileReadLine(sr);
                res = await this.ReadCSV(lines, dayToDayIndexFunc, updateIdToCircle);
            }

            if (res) {
                await this.ReadTimeFile();
            }

            return res;
        }
开发者ID:kavenblog,项目名称:ComicStarViewer,代码行数:31,代码来源:CheckList.cs


示例6: LoadData

        public async void LoadData(IEnumerable<XElement> sprites, StorageFile spriteSheetFile, string appExtensionId)
        {
            var bitmapImage = new BitmapImage();
            using (var stream = await spriteSheetFile.OpenReadAsync()) {
                await bitmapImage.SetSourceAsync(stream);
            }
            
            //xaml
            List<ImageListItem> listOfImages = new List<ImageListItem>();
            foreach (var sprite in sprites) {
                var row = int.Parse(sprite.Attributes("Row").First().Value);
                var col = int.Parse(sprite.Attributes("Column").First().Value);

                var brush = new ImageBrush();
                brush.ImageSource = bitmapImage;
                brush.Stretch = Stretch.UniformToFill;
                brush.AlignmentX = AlignmentX.Left;
                brush.AlignmentY = AlignmentY.Top;
                brush.Transform = new CompositeTransform() { ScaleX = 2.35, ScaleY = 2.35, TranslateX = col * (-140), TranslateY = row * (-87) };
                listOfImages.Add(new ImageListItem() {
                    Title = sprite.Attributes("Title").First().Value,
                    SpriteSheetBrush = brush,
                    File = sprite.Attributes("File").First().Value,
                    AppExtensionId = appExtensionId
                });
            }
            lbPictures.ItemsSource = listOfImages;
        }
开发者ID:liquidboy,项目名称:X,代码行数:28,代码来源:ImagePicker.xaml.cs


示例7: ProccesImage

        public async void ProccesImage(StorageFile imageFile)
        {
            var data = await FileIO.ReadBufferAsync(imageFile);

            // create a stream from the file
            var ms = new InMemoryRandomAccessStream();
            var dw = new DataWriter(ms);
            dw.WriteBuffer(data);
            await dw.StoreAsync();
            ms.Seek(0);

            // find out how big the image is, don't need this if you already know
            var bm = new BitmapImage();
            await bm.SetSourceAsync(ms);

            // create a writable bitmap of the right size
            var wb = new WriteableBitmap(bm.PixelWidth, bm.PixelHeight);
            ms.Seek(0);

            // load the writable bitpamp from the stream
            await wb.SetSourceAsync(ms);

            Bitmap bmp = (Bitmap)wb;

            //var filter1 = Grayscale.CommonAlgorithms.BT709;

            //bmp = filter1.Apply(bmp);

            wb = (WriteableBitmap)bmp;

            var file = await this.WriteableBitmapToStorageFile(wb, FileFormat.Jpeg);
        }
开发者ID:epustovit,项目名称:Scanner,代码行数:32,代码来源:ImageProccesing.cs


示例8: previewElement_Tapped

        private async void previewElement_Tapped(object sender, TappedRoutedEventArgs e)
        {
            // Block multiple taps.
            if (!IsCaptureInProgress)
            {
                IsCaptureInProgress = true;

                // Create the temporary storage file.
                media = await ApplicationData.Current.LocalFolder
                    .CreateFileAsync("capture_file.jpg", CreationCollisionOption.ReplaceExisting);

                // Take the picture and store it locally as a JPEG.
                await cameraCapture.CapturePhotoToStorageFileAsync(
                    ImageEncodingProperties.CreateJpeg(), media);

                captureButtons.Visibility = Visibility.Visible;

                // Use the stored image as the preview source.
                BitmapImage tempBitmap = new BitmapImage(new Uri(media.Path));
                imagePreview.Source = tempBitmap;
                imagePreview.Visibility = Visibility.Visible;
                previewElement.Visibility = Visibility.Collapsed;
                IsCaptureInProgress = false;
            }
        }
开发者ID:Ronacs,项目名称:WinDevCamp,代码行数:25,代码来源:MainPage.xaml.cs


示例9: SaveToFile

        public static async Task SaveToFile(
            this WriteableBitmap writeableBitmap,
            StorageFile outputFile,
            Guid encoderId)
        {
            try
            {
                Stream stream = writeableBitmap.PixelBuffer.AsStream();
                byte[] pixels = new byte[(uint)stream.Length];
                await stream.ReadAsync(pixels, 0, pixels.Length);

                using (var writeStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(encoderId, writeStream);
                    encoder.SetPixelData(
                        BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Premultiplied,
                        (uint)writeableBitmap.PixelWidth,
                        (uint)writeableBitmap.PixelHeight,
                        96,
                        96,
                        pixels);
                    await encoder.FlushAsync();

                    using (var outputStream = writeStream.GetOutputStreamAt(0))
                    {
                        await outputStream.FlushAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                string s = ex.ToString();
            }
        }
开发者ID:chao-zhou,项目名称:PomodoroTimer,代码行数:35,代码来源:WriteableBitmapSaveExtensions.cs


示例10: Load

		public static async Task<List<ROI>> Load(StorageFile file)
		{		
			// read content
			var lines = await Windows.Storage.FileIO.ReadLinesAsync(file);

			// Read in all the lines
			//string[] lines = System.IO.File.ReadAllLines(_fullPath);
			List<ROI> regionsOfInterest = new List<ROI>();

			foreach (var line in lines)
			{
				var fields = line.Split('\t');

				ROI roi = new ROI()
				{
					Index = Int32.Parse(fields[0]),
					Name = fields[1],
					Ident = Int32.Parse(fields[2]),
					X = Double.Parse(fields[6]),
					Y = Double.Parse(fields[7]),
					Z = Double.Parse(fields[8]),
                    TX = Double.Parse(fields[10]),
                    TY = Double.Parse(fields[11]),
                    TZ = Double.Parse(fields[12]),
				};
				
				regionsOfInterest.Add(roi);
			}

			return regionsOfInterest;
		}
开发者ID:digitalnelson,项目名称:BrainGraph,代码行数:31,代码来源:ROILoader.cs


示例11: fromStorageFile

        // Fetches all the data for the specified file
        public async static Task<FileItem> fromStorageFile(StorageFile f, CancellationToken ct)
        {
            FileItem item = new FileItem();
            item.Filename = f.DisplayName;
            
            // Block to make sure we only have one request outstanding
            await gettingFileProperties.WaitAsync();

            BasicProperties bp = null;
            try
            {
                bp = await f.GetBasicPropertiesAsync().AsTask(ct);
            }
            catch (Exception) { }
            finally
            {
                gettingFileProperties.Release();
            }

            ct.ThrowIfCancellationRequested();

            item.Size = (int)bp.Size;
            item.Key = f.FolderRelativeId;

            StorageItemThumbnail thumb = await f.GetThumbnailAsync(ThumbnailMode.SingleItem).AsTask(ct);
            ct.ThrowIfCancellationRequested();
            BitmapImage img = new BitmapImage();
            await img.SetSourceAsync(thumb).AsTask(ct);

            item.ImageData = img;
            return item;
        }
开发者ID:C-C-D-I,项目名称:Windows-universal-samples,代码行数:33,代码来源:FileItem.cs


示例12: LoadImage

 private async Task<BitmapImage> LoadImage(StorageFile file)
 {
     var image  = new BitmapImage();
     FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);
     image.SetSource(stream);
     return image;
 }
开发者ID:ma1982en,项目名称:curly-octo-pancake,代码行数:7,代码来源:ChoosingViewModel.cs


示例13: Save

        public async Task Save(StorageFile file)
        {
            var image = GetImage();

            // Measure the extent of the image (which may be cropped).
            Rect imageBounds;

            using (var commandList = new CanvasCommandList(sourceBitmap.Device))
            using (var drawingSession = commandList.CreateDrawingSession())
            {
                imageBounds = image.GetBounds(drawingSession);
            }

            // Rasterize the image into a rendertarget.
            using (var renderTarget = new CanvasRenderTarget(sourceBitmap.Device, (float)imageBounds.Width, (float)imageBounds.Height, 96))
            {
                using (var drawingSession = renderTarget.CreateDrawingSession())
                {
                    drawingSession.Blend = CanvasBlend.Copy;

                    drawingSession.DrawImage(image, -(float)imageBounds.X, -(float)imageBounds.Y);
                }

                // Save it out.
                var format = file.FileType.Equals(".png", StringComparison.OrdinalIgnoreCase) ? CanvasBitmapFileFormat.Png : CanvasBitmapFileFormat.Jpeg;

                using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    stream.Size = 0;

                    await renderTarget.SaveAsync(stream, format);
                }
            }
        }
开发者ID:shawnhar,项目名称:stuart,代码行数:34,代码来源:Photo.cs


示例14: DisplayStorageFileAsync

        private async Task DisplayStorageFileAsync(StorageFile storageFile)
        {
            var bitmapImage = new BitmapImage();
            bitmapImage.SetSource(await _storageFile.OpenAsync(FileAccessMode.Read));

            ImagePhoto.Source = bitmapImage;
        }
开发者ID:hwangtamu,项目名称:flickr-sdk,代码行数:7,代码来源:MainPage.xaml.cs


示例15: UnzipFromStorage

 public static async Task UnzipFromStorage(StorageFile pSource, StorageFolder pDestinationFolder, IEnumerable<string> pIgnore)
 {
     using (var stream = await pSource.OpenStreamForReadAsync())
     {
         await UnzipFromStream(stream, pDestinationFolder,pIgnore.ToList());
     }
 }
开发者ID:bigfool,项目名称:WPTelnetD,代码行数:7,代码来源:ZipHelper.cs


示例16: MusicProperties

        public MusicProperties(StorageFile file)
        {
            this.File = file;
            this.Path = this.File.Path;
            this.DateCreated = this.File.DateCreated;

            var properties = Task.Run(async () => await file.Properties.RetrievePropertiesAsync(new String[]
                {
                    "System.Music.AlbumTitle",
                    "System.Music.AlbumArtist",
                    "System.Music.Artist",
                    "System.Media.Duration",
                    "System.Music.Genre",
                    "System.DRM.IsProtected",
                    "System.Rating",
                    "System.Title",
                    "System.Music.TrackNumber"
                })).Result;

            object property;
            this.Album = (properties.TryGetValue("System.Music.AlbumTitle", out property) ? (string)property : (string)null) ?? "";
            this.Artist = (properties.TryGetValue("System.Music.Artist", out property) ? ((string[])property)[0] : (string)null) ?? "Unknown Artist";
            this.AlbumArtist = (properties.TryGetValue("System.Music.AlbumArtist", out property) ? (string)property : (string)null) ?? this.Artist;
            this.Duration = properties.TryGetValue("System.Media.Duration", out property) ? new TimeSpan((long)(ulong)property) : TimeSpan.Zero;
            this.Genre = (properties.TryGetValue("System.Music.Genre", out property) ? ((string[])property)[0] : (string)null) ?? "";
            this.IsProtected = properties.TryGetValue("System.DRM.IsProtected", out property) ? (bool)property : false;
            this.Rating = properties.TryGetValue("System.Rating", out property) ? (int)(uint)property : 0;
            this.Title = (properties.TryGetValue("System.Title", out property) ? (string)property : (string)null) ?? "";
            this.TrackNumber = properties.TryGetValue("System.Music.TrackNumber", out property) ? (int)(uint)property : 0;
        }
开发者ID:KennethYap,项目名称:MonoGame,代码行数:30,代码来源:MusicProperties.cs


示例17: GetImageAsync

 public async static Task<BitmapImage> GetImageAsync(StorageFile storageFile)
 {
     BitmapImage bitmapImage = new BitmapImage();
     FileRandomAccessStream stream = (FileRandomAccessStream)await storageFile.OpenAsync(FileAccessMode.Read);
     bitmapImage.SetSource(stream);
     return bitmapImage;
 }
开发者ID:Ivalaostia,项目名称:UniversalHelpers,代码行数:7,代码来源:Utilities.cs


示例18: PhoneApplicationPage_Loaded

        private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            string video_name = null;
            if (NavigationContext.QueryString.TryGetValue("Video", out video_name))
            {
                StorageFolder videosFolder = KnownFolders.VideosLibrary;

                IReadOnlyList<StorageFile> fileList = await videosFolder.GetFilesAsync();
                IReadOnlyList<StorageFolder> folderList = await videosFolder.GetFoldersAsync();

                var count = fileList.Count + folderList.Count;
                foreach (StorageFile file in fileList)
                {
                    if (file.Name == video_name)
                    {
                        try {
                            path.Text = file.Path;
                            videoPlayer.Source = new Uri(file.Path, UriKind.Absolute);
                            video = file;
                            x = await video.Properties.GetVideoPropertiesAsync();
                            videoPlayer.Play();
                            //pbVideo.Maximum = (int)videoPlayer.NaturalDuration.TimeSpan.TotalSeconds;
                            changeProgressBar();
                        }
                        catch(Exception e1)
                        {
                            MessageBox.Show(e1.ToString());
                        }
                    }
                }
            }
        }
开发者ID:fiefioor,项目名称:XNAmusic,代码行数:32,代码来源:VideoPlay.xaml.cs


示例19: Save

        /// <summary>
        /// Saves the specified bitmap to the specified location.
        /// </summary>
        /// <param name="source">The source bitmap image.</param>
        /// <param name="destination">The destination storage file for the image. JPEG, PNG, GIF, BMP and TIFF formats are supported.</param>
        /// <param name="width">The width of the image file.</param>
        /// <param name="height">The height of the image file.</param>
        /// <returns>True if the bitmap file was successfully saved. False otherwise.</returns>
        public async Task<bool> Save(WriteableBitmap source, StorageFile destination, int width, int height)
        {
            if (source == null || destination == null) return false;

            try
            {
                Guid encoderID = GetEncoderId(destination);

                using (IRandomAccessStream stream = await destination.OpenAsync(FileAccessMode.ReadWrite))
                {
                    Stream pixelStream = source.PixelBuffer.AsStream();
                    byte[] pixels = new byte[pixelStream.Length];
                    await pixelStream.ReadAsync(pixels, 0, pixels.Length);

                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(encoderID, stream);
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)source.PixelWidth, (uint)source.PixelHeight, Constants.DPI, Constants.DPI, pixels);

                    if (source.PixelWidth != width || source.PixelHeight != height)
                    {
                        encoder.BitmapTransform.ScaledWidth = (uint)width;
                        encoder.BitmapTransform.ScaledHeight = (uint)height;
                    }

                    await encoder.FlushAsync();
                }

                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return false;
        }
开发者ID:L-SEG,项目名称:Vitruvius,代码行数:43,代码来源:BitmapCapture.cs


示例20: SaveToFile

        private async Task<Uri> SaveToFile(StorageFile file)
        {
            Uri uri = null;

            if (inkCanvas.InkPresenter.StrokeContainer.GetStrokes().Count > 0)
            {
                try
                {
                    using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(stream);
                        uri = new Uri("ms-appdata:///local/" + file.Name);
                    }
                }
                catch (Exception ex)
                {
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                }
            }


            return uri;
        }
开发者ID:Ronacs,项目名称:WinDevCamp,代码行数:26,代码来源:InkNotesControl.xaml.cs



注:本文中的Windows.Storage.StorageFile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Storage.StorageFolder类代码示例发布时间:2022-05-26
下一篇:
C# Storage.ApplicationDataContainer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap