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


C# InMemoryRandomAccessStream.CloneStream方法代码示例

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


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

示例1: ResizeStreamAsync

        private async Task<IRandomAccessStream> ResizeStreamAsync(IRandomAccessStream stream, Size size, PhotoOrientation orientation)
        {
            var rotation = 0;

            switch (orientation)
            {
                case PhotoOrientation.Rotate180:
                    {
                        rotation = -180;
                    };
                    break;

                case PhotoOrientation.Rotate270:
                    {
                        rotation = -270;
                    };
                    break;

                case PhotoOrientation.Rotate90:
                    {
                        rotation = -90;
                    };
                    break;
            }

            using (var resizedStream = new InMemoryRandomAccessStream())
            {
                var buffer = new byte[stream.Size].AsBuffer();

                stream.Seek(0);

                await stream.ReadAsync(buffer, buffer.Length, InputStreamOptions.None);

                var resizeConfiguration = new AutoResizeConfiguration(
                    (uint)(size.Width * size.Height * 4 * 2), size,
                    new Size(0, 0), AutoResizeMode.Automatic, 0.7, ColorSpace.Yuv420);

                buffer = await JpegTools.AutoResizeAsync(buffer, resizeConfiguration);

                await resizedStream.WriteAsync(buffer);
                await resizedStream.FlushAsync();

                if (rotation != 0)
                {
                    resizedStream.Seek(0);

                    var filters = new List<IFilter>() { new RotationFilter(rotation) };

                    using (var source = new RandomAccessStreamImageSource(resizedStream))
                    using (var effect = new FilterEffect(source) { Filters = filters })
                    using (var renderer = new JpegRenderer(effect))
                    {
                        buffer = await renderer.RenderAsync();

                        using (var rotatedResizedStream = new InMemoryRandomAccessStream())
                        {
                            await rotatedResizedStream.WriteAsync(buffer);
                            await rotatedResizedStream.FlushAsync();

                            return rotatedResizedStream.CloneStream();
                        }
                    }
                }
                else
                {
                    return resizedStream.CloneStream();
                }
            }
        }
开发者ID:roachhd,项目名称:filter-explorer,代码行数:69,代码来源:PhotoModel.cs

示例2: SendInk

        private async void SendInk()
        {
            if (!this.isConnect) return;
            InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();

            await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(randomAccessStream);

            Stream stream = randomAccessStream.CloneStream().AsStream();

            byte[] data = new byte[stream.Length];

            stream.Read(data, 0, (int)stream.Length);

            SendData(data);
        }
开发者ID:XPOWERLM,项目名称:More-Personal-Computing,代码行数:15,代码来源:Scenario4.xaml.cs

示例3: GetThumbnailStreamAsync

        private async Task<IRandomAccessStream> GetThumbnailStreamAsync()
        {
#if DEBUG
            System.Diagnostics.Debug.WriteLine("GetThumbnailStreamAsync invoked " + this.GetHashCode());
#endif

            var maximumSide = (int)Windows.UI.Xaml.Application.Current.Resources["ThumbnailSide"];
            var orientation = await GetPhotoOrientationAsync();
            var orientationValue = orientation.HasValue ? orientation.Value : PhotoOrientation.Unspecified;

#if WINDOWS_PHONE_APP
            // TODO Getting platform thumbnails is currently broken in the WP8.1 preview SDK,
            //      thus generating thumbnails from the large original photos. Change to platform
            //      thumbnails again when platform is live & fine.

            var size = await GetPhotoResolutionAsync();

            using (var stream = await GetPhotoAsync())
            {
                return await ResizeStreamAsync(stream, new Size(maximumSide, maximumSide), orientationValue);
            }
#else
            using (var stream = await _file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.PicturesView))
            {
                if (stream.ContentType == "image/jpeg")
                {
                    if (stream.OriginalWidth <= maximumSide || stream.OriginalHeight <= maximumSide)
                    {
                        using (var memoryStream = new InMemoryRandomAccessStream())
                        {
                            using (var reader = new DataReader(stream))
                            using (var writer = new DataWriter(memoryStream))
                            {
                                await reader.LoadAsync((uint)stream.Size);
                                var buffer = reader.ReadBuffer((uint)stream.Size);

                                writer.WriteBuffer(buffer);
                                await writer.StoreAsync();
                                await writer.FlushAsync();

                                return memoryStream.CloneStream();
                            }
                        }
                    }
                    else
                    {
                        return await ResizeStreamAsync(stream, new Size(maximumSide, maximumSide), orientationValue);
                    }
                }
                else
                {
                    using (var preview = await GetPreviewAsync())
                    {
                        return await ResizeStreamAsync(preview, new Size(maximumSide, maximumSide), orientationValue);
                    }
                }
            }
#endif
        }
开发者ID:roachhd,项目名称:filter-explorer,代码行数:59,代码来源:PhotoModel.cs


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