当前位置: 首页>>代码示例>>C#>>正文


C# StorageFile.OpenReadAsync方法代码示例

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


在下文中一共展示了StorageFile.OpenReadAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StorageFileToWriteableBitmapWithDirection

        public static async Task<WriteableBitmap> StorageFileToWriteableBitmapWithDirection(StorageFile file)
        {
            if (file == null)
                return null;
            using (IRandomAccessStream stream = await file.OpenReadAsync())
            {

                // Create a decoder from the stream. With the decoder, we can get 
                // the properties of the image.
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                PixelDataProvider pix = await decoder.GetPixelDataAsync(
                BitmapPixelFormat.Bgra8,
                BitmapAlphaMode.Straight,
                new BitmapTransform(),
                ExifOrientationMode.RespectExifOrientation,
                ColorManagementMode.DoNotColorManage);

                byte[] pixels = pix.DetachPixelData();
                WriteableBitmap Bmp = new WriteableBitmap((int)decoder.OrientedPixelWidth, (int)decoder.OrientedPixelHeight);
                Stream pixStream = Bmp.PixelBuffer.AsStream();
                pixStream.Write(pixels, 0, (int)(decoder.OrientedPixelWidth * decoder.OrientedPixelHeight * 4));

                return Bmp;
            }
        }
开发者ID:chenjianwp,项目名称:UWP_ToolKit_CommonLibrary,代码行数:26,代码来源:ImageHelper.cs

示例2: 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

示例3: CropPhoto

        private static async Task<SoftwareBitmapSource> CropPhoto(StorageFile photo, FaceRectangle rectangle)
        {
            using (var imageStream = await photo.OpenReadAsync())
            {
                var decoder = await BitmapDecoder.CreateAsync(imageStream);
                if (decoder.PixelWidth >= rectangle.Left + rectangle.Width || decoder.PixelHeight >= rectangle.Top + rectangle.Height)
                {
                    var transform = new BitmapTransform
                    {
                        Bounds = new BitmapBounds
                        {
                            X = (uint)rectangle.Left,
                            Y = (uint)rectangle.Top,
                            Height = (uint)rectangle.Height,
                            Width = (uint)rectangle.Width
                        }
                    };

                    var softwareBitmapBGR8 = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, transform, ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage);
                    SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
                    await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);

                    return bitmapSource;
                }
                return null;
            }
        }
开发者ID:evgri243,项目名称:pubic-demos,代码行数:27,代码来源:FaceViewModel.cs

示例4: CreateBitmapAsync

        private async Task<WriteableBitmap> CreateBitmapAsync(StorageFile file)
        {
            // デコード後の画像のサイズを格納する
            int width, height;
            // デコード後のピクセルデータを格納する
            var bytes = default(byte[]);

            // ファイルストリームを開きます
            using (var stream = await file.OpenReadAsync())
            {
                // 非同期で新しいデコーダーを生成する
                var decoder = await BitmapDecoder.CreateAsync(stream);
                // 幅と高さを取得する
                width = (int)decoder.PixelWidth;
                height = (int)decoder.PixelHeight;
                // デコード後のピクセルデータを取得する
                var pixelData = await decoder.GetPixelDataAsync();
                bytes = pixelData.DetachPixelData();
            }

            // WriteableBitmapオブジェクトを生成し、デコード済みのピクセルデータを上書きする
            var bitmap = new WriteableBitmap(width, height);
            using (var pixelStream = bitmap.PixelBuffer.AsStream())
            {
                await pixelStream.WriteAsync(bytes, 0, bytes.Length);
            }

            return bitmap;
        }
开发者ID:runceel,项目名称:metroapps,代码行数:29,代码来源:MainPage.xaml.cs

示例5: GetData

        public  async Task<RecipeBox> GetData()
        {

            if (await DoesFileExistAsync(FileName))
            {
                file = await ApplicationData.Current.LocalFolder.CreateFileAsync(FileName, CreationCollisionOption.OpenIfExists);

                IInputStream sessionInputStream = await file.OpenReadAsync();

                //Using DataContractSerializer , look at the cat-class
                // var sessionSerializer = new DataContractSerializer(typeof(List<object>), new Type[] { typeof(T) });
                //_data = (List<object>)sessionSerializer.ReadObject(sessionInputStream.AsStreamForRead());

                

                var serializer = new XmlSerializer(typeof(RecipeBox));
                var rb =(RecipeBox)serializer.Deserialize(sessionInputStream.AsStreamForRead());
                sessionInputStream.Dispose();
                return rb;
            }
            else
            {
                var rb = generateDefault();
                return rb;
            }

        }
开发者ID:CADTraveller,项目名称:RecipeMaster,代码行数:27,代码来源:XmlStorageService.cs

示例6: DetectSignature

        public async static Task<bool> DetectSignature(StorageFile file, int corner)
        {
            bool success = false;

            try
            {
                var randomAccessStream = await file.OpenReadAsync();
                var readStream = randomAccessStream.AsStreamForRead();
                byte[] fileBytes = new byte[readStream.Length];
                await readStream.ReadAsync(fileBytes,0,fileBytes.Length);
                
                StringBuilder serializedBytes = new StringBuilder();
                fileBytes.ToList().ForEach(x => serializedBytes.AppendFormat("{0}.", Convert.ToUInt32(x)));
                string postParameters = String.Format("fileBytes={0}&fileName={1}", serializedBytes.ToString(), file.Name);
                byte[] postData = Encoding.UTF8.GetBytes(postParameters);

                HttpWebRequest req = CreateWebRequest("/Detection/MobileDetectMark");
                var stream = await req.GetRequestStreamAsync();
                await stream.WriteAsync(postData, 0, postData.Length);
                stream.Dispose();

                HttpWebResponse result = (HttpWebResponse) await req.GetResponseAsync();
                if (result.StatusCode == HttpStatusCode.OK && result.Cookies["user"] != null  && result.Cookies["imageNumber"] != null)
                {
                    PageData.Instance().SetDetectionResultsPageData(result.Cookies["user"].Value, int.Parse(result.Cookies["imageNumber"].Value));
                    success = true;
                }
            }
            catch (Exception E)
            {
                Popup errorPopup = new Popup();

            }
            return success;
        }
开发者ID:tomazio21,项目名称:DocFingerPrinterBeta,代码行数:35,代码来源:HttpRequest.cs

示例7: 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

示例8: ResizeImageUniformAsync

        public static async Task ResizeImageUniformAsync(StorageFile sourceFile, StorageFile targetFile, int maxWidth = Int32.MaxValue, int maxHeight = Int32.MaxValue)
        {
            using (var stream = await sourceFile.OpenReadAsync())
            {
                var decoder = await BitmapDecoder.CreateAsync(stream);

                if (IsGifImage(decoder))
                {
                    await sourceFile.CopyAndReplaceAsync(targetFile);
                    return;
                }

                maxWidth = Math.Min(maxWidth, (int)decoder.OrientedPixelWidth);
                maxHeight = Math.Min(maxHeight, (int)decoder.OrientedPixelHeight);
                var imageSize = new Size(decoder.OrientedPixelWidth, decoder.OrientedPixelHeight);
                var finalSize = imageSize.ToUniform(new Size(maxWidth, maxHeight));

                if (finalSize.Width == decoder.OrientedPixelWidth && finalSize.Height == decoder.OrientedPixelHeight)
                {
                    await sourceFile.CopyAndReplaceAsync(targetFile);
                    return;
                }

                await ResizeImageAsync(decoder, targetFile, finalSize);
            }
        }
开发者ID:ridomin,项目名称:waslibs,代码行数:26,代码来源:BitmapTools.cs

示例9: SetSourceAsync

        public static async Task<BitmapImage> SetSourceAsync(this BitmapImage bitmap, StorageFile file)
        {
            using (var stream = await file.OpenReadAsync())
            {
                await bitmap.SetSourceAsync(stream);
            }

            return bitmap;
        }
开发者ID:chao-zhou,项目名称:PomodoroTimer,代码行数:9,代码来源:BitmapImageLoadExtensions.cs

示例10: UploadActivityAsync

        /// <summary>
        /// Uploads an activity.
        /// </summary>
        /// <param name="file">The path to the activity file on your local hard disk.</param>
        /// <param name="dataFormat">The format of the file.</param>
        /// <param name="activityType">The type of the activity.</param>
        /// <returns>The status of the upload.</returns>
        public async Task<UploadStatus> UploadActivityAsync(StorageFile file, DataFormat dataFormat, ActivityType activityType = ActivityType.Ride)
        {
            String format = String.Empty;

            switch (dataFormat)
            {
                case DataFormat.Fit:
                    format = "fit";
                    break;
                case DataFormat.FitGZipped:
                    format = "fit.gz";
                    break;
                case DataFormat.Gpx:
                    format = "gpx";
                    break;
                case DataFormat.GpxGZipped:
                    format = "gpx.gz";
                    break;
                case DataFormat.Tcx:
                    format = "tcx";
                    break;
                case DataFormat.TcxGZipped:
                    format = "tcx.gz";
                    break;
            }
           
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Add("Authorization", String.Format("Bearer {0}", Authentication.AccessToken));

            MultipartFormDataContent content = new MultipartFormDataContent();

            byte[] fileBytes = null;
            using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync())
            {
                fileBytes = new byte[stream.Size];
                using (DataReader reader = new DataReader(stream))
                {
                    await reader.LoadAsync((uint)stream.Size);
                    reader.ReadBytes(fileBytes);
                }
            }

            var byteArrayContent = new ByteArrayContent(fileBytes);

            content.Add(byteArrayContent, "file", file.Name);

            HttpResponseMessage result = await client.PostAsync(
                String.Format("https://www.strava.com/api/v3/uploads?data_type={0}&activity_type={1}",
                format,
                activityType.ToString().ToLower()),
                content);

            String json = await result.Content.ReadAsStringAsync();

            return Unmarshaller<UploadStatus>.Unmarshal(json);
        }
开发者ID:TiBall,项目名称:stravadotnet,代码行数:63,代码来源:UploadClient.cs

示例11: Show

        public void Show(StorageFile file) {
            parent = new Popup();
            parent.Child = this;
            parent.IsOpen = true;
            
            IRandomAccessStream stream = file.OpenReadAsync().AsTask().Result;
            Preview.SetSource(stream, file.ContentType);

            MediaName.Text = file.Name;
        }
开发者ID:huylu,项目名称:media-for-mobile,代码行数:10,代码来源:PlayerPopup.xaml.cs

示例12: ToArrayAsync

        public async Task<byte[]> ToArrayAsync(StorageFile storageFile)
        {
            var stream = await storageFile.OpenReadAsync();

            using (var dataReader = new DataReader(stream))
            {
                var bytes = new byte[stream.Size];
                await dataReader.LoadAsync((uint)stream.Size);
                dataReader.ReadBytes(bytes);

                return bytes;
            }
        }
开发者ID:derikwhittaker,项目名称:Memory,代码行数:13,代码来源:StorageFileHelper.cs

示例13: LoadAsync

        public static async Task<WriteableBitmap> LoadAsync(
            this WriteableBitmap writeableBitmap,
            StorageFile storageFile)
        {
            var wb = writeableBitmap;

            using (var stream = await storageFile.OpenReadAsync())
            {
                await wb.SetSourceAsync(stream);
            }

            return wb;
        }
开发者ID:chao-zhou,项目名称:PomodoroTimer,代码行数:13,代码来源:WriteableBitmapLoadExtensions.cs

示例14: ToByteArrayAsync

        //public IAsyncOperation<string> CapturePicture()
        //{
        //    return getStringHelper().AsAsyncOperation();
            
        //}

        //private async Task<string> getStringHelper()
        //{
        //    var dialog = new CameraCaptureUI();
        //    var file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
        //    // Do something useful w/ the file
        //    byte[] imageStream = await ToByteArrayAsync(file);
        //    string base64String = Convert.ToBase64String(imageStream);
        //    return base64String;
            
        //} 

        
        private static async Task<byte[]> ToByteArrayAsync(StorageFile file)
        {
            using (IRandomAccessStream stream = await file.OpenReadAsync())
            {
                using (DataReader reader = new DataReader(stream.GetInputStreamAt(0)))
                {
                    await reader.LoadAsync((uint)stream.Size);
                    byte[] Bytes = new byte[stream.Size];
                    reader.ReadBytes(Bytes);
                    return Bytes;
                }
            }
        }
开发者ID:boyofgreen,项目名称:Win10WebViewCallCSharp,代码行数:31,代码来源:CommunicationWinRT.cs

示例15: GetCroppedBitmapAsync

        /// <summary>
        /// Get a cropped bitmap from a image file.
        /// </summary>
        /// <param name="originalImageFile">
        /// The original image file.
        /// </param>
        /// <param name="startPoint">
        /// The start point of the region to be cropped.
        /// </param>
        /// <param name="corpSize">
        /// The size of the region to be cropped.
        /// </param>
        /// <returns>
        /// The cropped image.
        /// </returns>
        async public static Task<ImageSource> GetCroppedBitmapAsync(StorageFile originalImageFile,
            Point startPoint, Size corpSize, double scale)
        {
            if (double.IsNaN(scale) || double.IsInfinity(scale))
            {
                scale = 1;
            }

            // Convert start point and size to integer.
            uint startPointX = (uint)Math.Floor(startPoint.X * scale);
            uint startPointY = (uint)Math.Floor(startPoint.Y * scale);
            uint height = (uint)Math.Floor(corpSize.Height * scale);
            uint width = (uint)Math.Floor(corpSize.Width * scale);

            using (IRandomAccessStream stream = await originalImageFile.OpenReadAsync())
            {

                // Create a decoder from the stream. With the decoder, we can get 
                // the properties of the image.
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
          
                // The scaledSize of original image.
                uint scaledWidth = (uint)Math.Floor(decoder.PixelWidth * scale);
                uint scaledHeight = (uint)Math.Floor(decoder.PixelHeight * scale);
              

                // Refine the start point and the size. 
                if (startPointX + width > scaledWidth)
                {
                    startPointX = scaledWidth - width;
                }

                if (startPointY + height > scaledHeight)
                {
                    startPointY = scaledHeight - height;
                }

                // Get the cropped pixels.
                byte[] pixels = await GetPixelData(decoder, startPointX, startPointY, width, height,
                    scaledWidth, scaledHeight);

                // Stream the bytes into a WriteableBitmap
                WriteableBitmap cropBmp = new WriteableBitmap((int)width, (int)height);
                Stream pixStream = cropBmp.PixelBuffer.AsStream();
                pixStream.Write(pixels, 0, (int)(width * height * 4));

                return cropBmp;
            }

        }
开发者ID:eirikdal,项目名称:ReciCamApp,代码行数:65,代码来源:CropBitmap.cs


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