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


C# InMemoryRandomAccessStream.Dispose方法代码示例

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


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

示例1: LoadFromResource

        public void LoadFromResource(string assemblyName, MvxResourcePath resourceName)
        {
            //Package.Current.InstalledLocation.GetFileAsync()
            var path = resourceName.GetResourcePath(".", true);
            //   bitmap = new BitmapImage(new Uri("ms-appx:///" + assemblyName + "/" + path, UriKind.RelativeOrAbsolute));
            var strm = Assembly.Load(new AssemblyName(assemblyName)).GetManifestResourceStream(path);
            byte[] bts = new byte[strm.Length];
            strm.Read(bts, 0, (int)strm.Length);
            InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();

            ras.GetOutputStreamAt(0).WriteAsync(bts.AsBuffer());
            //strm.CopyToAsync(ras.AsStreamForWrite()).Wait();

            ras.Seek(0);
            bitmap = new BitmapImage();
            bitmap.SetSource(ras);
            ras.Dispose();
            strm.Dispose();
        }
开发者ID:hugoterelle,项目名称:mvvmcross-bitmap-plugin,代码行数:19,代码来源:MvxWindowsStoreBitmap.cs

示例2: DataToImage

        private async Task<Image> DataToImage(Tile tile)
        {
            BitmapImage bitmapImage = new BitmapImage();
            if (tile.IsSuccessd)
            {
                InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
                DataWriter writer = new DataWriter(randomAccessStream.GetOutputStreamAt(0));
                writer.WriteBytes(tile.MapImage.Data);
                await writer.StoreAsync();

                bitmapImage.SetSource(randomAccessStream);
                writer.Dispose();
                randomAccessStream.Dispose();
            }
            Image image = new Image()
            {
                Opacity = 1.0,
                Tag = tile,
                IsHitTestVisible = false,
                Name = tile.TileKey,
                Stretch = Stretch.Fill,
                Source = bitmapImage
            };

            double resolution = tile.Resolution;
            LayerContainer.SetBounds(image, GetTilesBounds(tile.Column, tile.Row, tile.Resolution));//计算该image的范围
            return image;
        }
开发者ID:SuperMap,项目名称:iClient-for-Win8,代码行数:28,代码来源:TiledLayer.cs

示例3: LoadImageFromUriAsync

 private async void LoadImageFromUriAsync(Uri url)
 {
     HttpClient httpClient = new HttpClient();
     HttpResponseMessage result = httpClient.GetAsync(url).Result;
     byte[] array = await result.Content.ReadAsByteArrayAsync();
     InMemoryRandomAccessStream inMemoryRandomAccessStream = new InMemoryRandomAccessStream();
     DataWriter dataWriter = new DataWriter(inMemoryRandomAccessStream.GetOutputStreamAt(0uL));
     dataWriter.WriteBytes(array);
     await dataWriter.StoreAsync();
     BitmapImage bitmapImage = new BitmapImage();
     bitmapImage.SetSource(inMemoryRandomAccessStream);
     this._image = bitmapImage;
     httpClient.Dispose();
     result.Dispose();
     array = null;
     inMemoryRandomAccessStream.Dispose();
     dataWriter.Dispose();
     bitmapImage = null;
 }
开发者ID:rolandsmeenk,项目名称:ModernApps,代码行数:19,代码来源:YouTubeService.cs

示例4: GetCameraImage

        /// <summary>
        /// Perform image capture from mediaCapture object
        /// </summary>
        /// <param name="cancelToken">
        /// The cancel Token.
        /// </param>
        /// <returns>
        /// Decoded barcode string.
        /// </returns>
        private async Task<Result> GetCameraImage(CancellationToken cancelToken)
        {
            if (cancelToken.IsCancellationRequested)
            {
                throw new OperationCanceledException(cancelToken);
            }

            imageStream = new InMemoryRandomAccessStream();

            await capture.CapturePhotoToStreamAsync(encodingProps, imageStream);
            await imageStream.FlushAsync();

            var decoder = await BitmapDecoder.CreateAsync(imageStream);

            byte[] pixels = (await decoder.GetPixelDataAsync(BitmapPixelFormat.Rgba8,
                BitmapAlphaMode.Ignore,
                new BitmapTransform(),
                ExifOrientationMode.IgnoreExifOrientation,
                ColorManagementMode.DoNotColorManage)).DetachPixelData();

            const BitmapFormat format = BitmapFormat.RGB32;

            imageStream.Dispose();

            var result =
                await
                    Task.Run(
                        () => barcodeReader.Decode(pixels, (int)decoder.PixelWidth, (int)decoder.PixelHeight, format),
                        cancelToken);

            return result;
        }
开发者ID:TomKaminski,项目名称:ItadMobileApp,代码行数:41,代码来源:Reader.cs

示例5: wvMain_SendMessage


//.........这里部分代码省略.........
                                //await wvMain.CapturePreviewToStreamAsync(ms);

                                //img: Banner 400 width
                                //ms.Seek(0);
                                await X.Services.Image.Service.Instance.GenerateResizedImageAsync(400, wvMain.ActualWidth, wvMain.ActualHeight, ms, uriHash + ".png", X.Services.Image.Service.location.MediumFolder);

                                //img: Thumbnail
                                ms.Seek(0);
                                await X.Services.Image.Service.Instance.GenerateResizedImageAsync(180, wvMain.ActualWidth, wvMain.ActualHeight, ms, uriHash + ".png", X.Services.Image.Service.location.ThumbFolder);

                                //img: Tile
                                ms.Seek(0);
                                await X.Services.Image.Service.Instance.GenerateResizedImageAsync(71, wvMain.ActualWidth, wvMain.ActualHeight, ms, uriHash + ".png", X.Services.Image.Service.location.TileFolder, 71);

                                ms.Seek(0);
                                await X.Services.Image.Service.Instance.GenerateResizedImageAsync(150, wvMain.ActualWidth, wvMain.ActualHeight, ms, uriHash + "-150x150.png", X.Services.Image.Service.location.TileFolder, 150);

                                ms.Seek(0);
                                await X.Services.Image.Service.Instance.GenerateResizedImageAsync(310, wvMain.ActualWidth, wvMain.ActualHeight, ms, uriHash + "-310x150.png", X.Services.Image.Service.location.TileFolder, 150);

                                ms.Seek(0);
                                await X.Services.Image.Service.Instance.GenerateResizedImageAsync(310, wvMain.ActualWidth, wvMain.ActualHeight, ms, uriHash + "-310x310.png", X.Services.Image.Service.location.TileFolder, 310);


                                //update tile
                                //var sxxxxx = Windows.Storage.ApplicationData.Current.LocalFolder;
                                X.Services.Tile.Service.UpdatePrimaryTile("X.Browser",
                                    "ms-appdata:///local/tile/" + uriHash + "-150x150.png",
                                    "ms-appdata:///local/tile/" + uriHash + "-310x150.png",
                                    "ms-appdata:///local/tile/" + uriHash + "-310x310.png",
                                    "ms-appdata:///local/tile/" + uriHash + ".png"
                                    );

                                ms.Dispose();

                            }


                            //update thumb in VM
                            var fullUriHash = string.Concat(X.Services.Image.Service.Instance.MediumLocation, "\\", uriHash, ".png");
                            //if (!vm.SelectedTab.ThumbUri.Equals(fullUriHash)) {
                            vm.SelectedTab.ThumbUri = fullUriHash + "?v=" + Guid.NewGuid().ToString();
                            vm.SelectedTab.ExternalRaisePropertyChanged("ThumbUri");
                            //}

                            vm.SelectedTab.LastRefreshedDate = DateTime.UtcNow;

                        }



                        isCapturingImage = false;
                    }
                    
                }
                else if (ea.Type == "SnapViewer")
                {
                    if (!isCapturingImage) {
                        isCapturingImage = true;

                        var uriHash = FlickrNet.UtilityMethods.MD5Hash(vm.SelectedTab.OriginalUri); //   e.Uri);
                        using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
                        {
                            await wvMain.Renderer?.CaptureThumbnail(ms);

                            //img: Banner 400 width
开发者ID:liquidboy,项目名称:X,代码行数:67,代码来源:Mainlayout.xaml.WebView.cs

示例6: Run

        private async void Run()
        {
            await _HubConnection.Start();

            var cam = new MediaCapture();

            await cam.InitializeAsync(new MediaCaptureInitializationSettings()
            {
                MediaCategory = MediaCategory.Media,
                StreamingCaptureMode = StreamingCaptureMode.Video
            });

            _Sensor.MotionDetected += async (int pinNum) =>
            {
                var stream = new InMemoryRandomAccessStream();
                Stream imageStream = null;
                try
                {
                    await Task.Factory.StartNew(async () =>
                    {
                        _Sensor.IsActive = false;
                        await cam.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
                        stream.Seek(0);
                        imageStream = stream.AsStream();
                        imageStream.Seek(0, SeekOrigin.Begin);
                        string imageUrl = await NotificationHelper.UploadImageAsync(imageStream);

                        switch (await OxfordHelper.IdentifyAsync(imageUrl))
                        {
                            case AuthenticationResult.IsOwner:
                                // open the door
                                MotorController.PWM(26);
                                break;

                            case AuthenticationResult.Unkown:
                                // send notification to the owner
                                NotificationHelper.NotifyOwnerAsync(imageUrl);
                                break;

                            case AuthenticationResult.None:
                            default:
                                break;
                        }
                        _Sensor.IsActive = true;
                    });
                }
                finally
                {
                    if (stream != null)
                        stream.Dispose();
                    if (imageStream != null)
                        imageStream.Dispose();
                }
            };
        }
开发者ID:BertusV,项目名称:Home-Visits-Manager,代码行数:55,代码来源:VisitorsController.cs

示例7: LoadImageFromHttpResponse

        private async Task LoadImageFromHttpResponse(HttpResponseMessage response, BitmapImage bitmap, string cacheKey)
        {
            if (response.IsSuccessStatusCode)
            {
                var stream = new InMemoryRandomAccessStream();

                using (var content = response.Content)
                {
                    await content.WriteToStreamAsync(stream);
                }

                await stream.FlushAsync();
                stream.Seek(0);

                await bitmap.Dispatcher.RunAsync(CoreDispatcherPriority.Low, async () =>
                {
                    try
                    {
                        await bitmap.SetSourceAsync(stream);

                        // cache image asynchronously, after successful decoding
                        var task = Task.Run(async () =>
                        {
                            var buffer = new Windows.Storage.Streams.Buffer((uint)stream.Size);

                            stream.Seek(0);
                            await stream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.None);
                            stream.Dispose();

                            await Cache.SetAsync(cacheKey, buffer);
                        });
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("{0}: {1}", response.RequestMessage.RequestUri, ex.Message);
                        stream.Dispose();
                    }
                });
            }
            else
            {
                Debug.WriteLine("{0}: {1}", response.RequestMessage.RequestUri, response.StatusCode);
            }
        }
开发者ID:bhanu475,项目名称:XamlMapControl,代码行数:44,代码来源:TileImageLoader.WinRT.cs

示例8: UriImageSaveLocalAsync

        /// <summary>
        /// 문자열 이미지 uri를 받아서 이미지를 로컬에 저장하고 BitmapImage로 반환한다.
        /// </summary>
        /// <param name="imageUri"></param>
        /// <returns></returns>
        public async Task<BitmapImage> UriImageSaveLocalAsync(string imageUri, bool retry = true)
        {
            if (string.IsNullOrEmpty(imageUri) == true) return null;

            //폴더 초기화 될때까지 대기
            while (files == null)
            {
                await TaskEx.Delay(500);
            }

            //Stream
            var iuri = new Uri(imageUri, UriKind.Absolute);
            string filename = System.IO.Path.GetFileName(iuri.LocalPath);
            //메모리 내용확인
            var mbi = GetImage(filename);
            if (mbi != null)
            {
                return mbi;
            }

            Stream imageStream = null;      //기본 스트림
            //IRandomAccessStream
            InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
            //create bitmap
            BitmapImage bi = new BitmapImage();

            //폴더에 파일 존재 확인
            if (files.Any(p => p.Name == filename))
            {
                var localFile = files.First(p => p.Name == filename);
                bi.UriSource = new Uri(Path.Combine(ApplicationData.Current.TemporaryFolder.Path, localFile.Name));
                AddImage(filename, bi);
                //try
                //{
                //    imageStream = await localFile.OpenStreamForReadAsync();
                //}
                //catch (Exception)
                //{
                //    //파일 열때 에러가 발생하면, 파일이 존재하지 않기 때문일 수 있는..
                //    UpdateFolder();
                //    bi.UriSource = new Uri(imageUri);
                //    if (imageStream != null) imageStream.Dispose();
                //    if (ras != null) ras.Dispose();
                //    return bi;
                //}

                //await imageStream.CopyToAsync(ras.AsStreamForWrite());
                //if (ras.Size > 0)
                //{
                //    ras.Seek(0);
                //    await bi.SetSourceAsync(ras);
                //    //메모리에 저장
                //    AddImage(filename, bi);
                //}
                //else
                //{
                //    //파일 이상인듯
                //    await localFile.DeleteAsync();
                //    UpdateFolder();
                //    //재귀호출
                //    if (retry == false)
                //    {
                //        if (imageStream != null) imageStream.Dispose();
                //        if (ras != null) ras.Dispose();
                //        return await UriImageSaveLocalAsync(imageUri, true);
                //    }
                //    else
                //    {
                //        bi.UriSource = new Uri(imageUri);
                //        if (imageStream != null) imageStream.Dispose();
                //        if (ras != null) ras.Dispose();
                //        return bi;
                //    }
                //}
            }
            else
            {
                using (HttpClient hc = new HttpClient())
                {
                    try
                    {
                        imageStream = await hc.GetStreamAsync(imageUri);
                    }
                    catch (Exception)
                    {
                        //네트워크 상태가 끊어졌을 때
                        bi.UriSource = new Uri(imageUri);
                        if (imageStream != null) imageStream.Dispose();
                        if (ras != null) ras.Dispose();
                        return bi;
                    }
                    //Stream -> IRandomAccessStream
                    await imageStream.CopyToAsync(ras.AsStreamForWrite());
                    if (ras.Size > 0)
                    {
//.........这里部分代码省略.........
开发者ID:vapps,项目名称:CrossPlatform,代码行数:101,代码来源:StaticFunctionsStore.cs

示例9: ShowVehicleLocations

        private async Task ShowVehicleLocations()
        {
            var vehicleLocations = await searchVm.GetBusLocations();

            while (vehicleCounter > 0)
            {
                SearchMap.MapElements.RemoveAt(SearchMap.MapElements.Count - 1);
                vehicleCounter--;
            }

            var inboundBM = new WriteableBitmap(40, 40);
            await inboundBM.SetSourceAsync(await RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Inbound.png")).OpenReadAsync());

            var outboundBM = new WriteableBitmap(40, 40);
            await outboundBM.SetSourceAsync(await RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Outbound.png")).OpenReadAsync());

            foreach (Bus bus in vehicleLocations)
            {
                if (bus.direction.Equals("inbound"))
                {
                    var rotatedImage = inboundBM.RotateFree(bus.busHeading, false);
                    var stream = new InMemoryRandomAccessStream();
                    await rotatedImage.ToStream(stream, BitmapEncoder.PngEncoderId);

                    var busMarker = new MapIcon
                    {
                        Image = RandomAccessStreamReference.CreateFromStream(stream),
                        CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible,
                        Location = new Geopoint(new BasicGeoposition { Latitude = bus.latitude, Longitude = bus.longitude }),
                        NormalizedAnchorPoint = new Point(0.5, 0.5),
                        ZIndex = 99
                    };

                    SearchMap.MapElements.Add(busMarker);

                    await stream.FlushAsync();
                    stream.Dispose();
                    rotatedImage = null;
                }
                else if (bus.direction.Equals("outbound"))
                {
                    var rotatedImage = outboundBM.RotateFree(bus.busHeading, false);
                    var stream = new InMemoryRandomAccessStream();
                    await rotatedImage.ToStream(stream, BitmapEncoder.PngEncoderId);

                    var busMarker = new MapIcon
                    {
                        Image = RandomAccessStreamReference.CreateFromStream(stream),
                        CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible,
                        Location = new Geopoint(new BasicGeoposition { Latitude = bus.latitude, Longitude = bus.longitude }),
                        NormalizedAnchorPoint = new Point(0.5, 0.5),
                        ZIndex = 99
                    };

                    SearchMap.MapElements.Add(busMarker);

                    await stream.FlushAsync();
                    stream.Dispose();
                    rotatedImage = null;
                }
                vehicleCounter++;
            }

            inboundBM = null;
            outboundBM = null;
        }
开发者ID:nexDevelopment,项目名称:nexMUNI,代码行数:66,代码来源:MainPage.xaml.cs

示例10: ScanButton


//.........这里部分代码省略.........
                bool keepGoing = true;
                Action a = null;
                a = async () =>
                {
                    if (!keepGoing) return;
                    var stream = new InMemoryRandomAccessStream();
                    await imageSource.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

                    stream.Seek(0);

                    var tmpBmp = new WriteableBitmap(1, 1);
                    await tmpBmp.SetSourceAsync(stream);
                    var writeableBmp = new WriteableBitmap(tmpBmp.PixelWidth, tmpBmp.PixelHeight);
                    stream.Seek(0);
                    await writeableBmp.SetSourceAsync(stream);

                    Result _result = null;

                    var barcodeReader = new BarcodeReader
                    {
                        // TryHarder = true,
                        AutoRotate = true
                    };

                    try
                    {
                        _result = barcodeReader.Decode(writeableBmp);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }

                    stream.Dispose();

                    if (_result != null)
                    {
                        result = _result.Text;
                        Debug.WriteLine(_result.Text);
                        keepGoing = false;
                        tcs.TrySetResult(null);
                    }
                    else
                    {
                        var x = RunOnUIThread(a);
                    }
                };

                await RunOnUIThread(a);
#endif

                CustomMessageBox messageBox = new CustomMessageBox()
                {
                    Title = "Scan Tag",
                    Message = "",
                    Content = sp,
                    LeftButtonContent = "OK",
                    RightButtonContent = "Cancel",
                    IsFullScreen = false,
                };

                messageBox.Unloaded += (s2, e2) =>
                {
                    tcs.TrySetResult(null);
                };
                messageBox.Show();
开发者ID:jcookems,项目名称:freezing-ninja,代码行数:67,代码来源:MainPage.xaml.cs


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