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


C# IFileSystem.GetFileStream方法代码示例

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


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

示例1: GetDimensions

        /// <summary>
        /// Gets the dimensions of an image.
        /// </summary>
        /// <param name="path">The path of the image to get the dimensions of.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="fileSystem">The file system.</param>
        /// <returns>The dimensions of the specified image.</returns>
        /// <exception cref="ArgumentException">The image was of an unrecognised format.</exception>
        public static Size GetDimensions(string path, ILogger logger, IFileSystem fileSystem)
        {
            try
            {
                using (var fs = File.OpenRead(path))
                {
                    using (var binaryReader = new BinaryReader(fs))
                    {
                        return GetDimensions(binaryReader);
                    }
                }
            }
            catch
            {
                logger.Info("Failed to read image header for {0}. Doing it the slow way.", path);
            }

            // Buffer to memory stream to avoid image locking file
            using (var fs = fileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var memoryStream = new MemoryStream())
                {
                    fs.CopyTo(memoryStream);

                    // Co it the old fashioned way
                    using (var b = Image.FromStream(memoryStream, true, false))
                    {
                        return b.Size;
                    }
                }
            }
        }
开发者ID:kreeturez,项目名称:MediaBrowser,代码行数:40,代码来源:ImageHeader.cs

示例2: GetThumbCollage

        public static async Task<Stream> GetThumbCollage(List<string> files,
            IFileSystem fileSystem,
            int width,
            int height)
        {
            if (files.Count < 3)
            {
                return await GetSingleImage(files, fileSystem).ConfigureAwait(false);
            }

            const int rows = 1;
            const int cols = 3;

            int cellWidth = 2 * (width / 3);
            int cellHeight = height;
            var index = 0;

            var img = new Bitmap(width, height, PixelFormat.Format32bppPArgb);

            using (var graphics = Graphics.FromImage(img))
            {
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                graphics.CompositingMode = CompositingMode.SourceCopy;

                for (var row = 0; row < rows; row++)
                {
                    for (var col = 0; col < cols; col++)
                    {
                        var x = col * (cellWidth / 2);
                        var y = row * cellHeight;

                        if (files.Count > index)
                        {
                            using (var fileStream = fileSystem.GetFileStream(files[index], FileMode.Open, FileAccess.Read, FileShare.Read, true))
                            {
                                using (var memoryStream = new MemoryStream())
                                {
                                    await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false);

                                    memoryStream.Position = 0;

                                    using (var imgtemp = Image.FromStream(memoryStream, true, false))
                                    {
                                        graphics.DrawImage(imgtemp, x, y, cellWidth, cellHeight);
                                    }
                                }
                            }
                        }

                        index++;
                    }
                }
            }

            return GetStream(img);
        }
开发者ID:Ceten,项目名称:MediaBrowser,代码行数:59,代码来源:DynamicImageHelpers.cs

示例3: CreateThumbCollage

        public static void CreateThumbCollage(List<string> files,
            IFileSystem fileSystem,
            string file,
            int width,
            int height)
        {
            const int numStrips = 4;
            files = ImageHelpers.ProjectPaths(files, numStrips);

            const int rows = 1;
            int cols = numStrips;

            int cellWidth = 2 * (width / 3);
            int cellHeight = height;
            var index = 0;

            using (var img = new Bitmap(width, height, PixelFormat.Format32bppPArgb))
            {
                using (var graphics = Graphics.FromImage(img))
                {
                    graphics.CompositingQuality = CompositingQuality.HighQuality;
                    graphics.SmoothingMode = SmoothingMode.HighQuality;
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    graphics.CompositingMode = CompositingMode.SourceCopy;

                    for (var row = 0; row < rows; row++)
                    {
                        for (var col = 0; col < cols; col++)
                        {
                            var x = col * (cellWidth / 2);
                            var y = row * cellHeight;

                            if (files.Count > index)
                            {
                                using (var fileStream = fileSystem.GetFileStream(files[index], FileMode.Open, FileAccess.Read, FileShare.Read, true))
                                {
                                    using (var memoryStream = new MemoryStream())
                                    {
                                        fileStream.CopyTo(memoryStream);

                                        memoryStream.Position = 0;

                                        using (var imgtemp = Image.FromStream(memoryStream, true, false))
                                        {
                                            graphics.DrawImage(imgtemp, x, y, cellWidth, cellHeight);
                                        }
                                    }
                                }
                            }

                            index++;
                        }
                    }
                    img.Save(file);
                }
            }
        }
开发者ID:paul-777,项目名称:Emby,代码行数:58,代码来源:DynamicImageHelpers.cs

示例4: GetImage

        private static async Task<Image> GetImage(string file, IFileSystem fileSystem)
        {
            using (var fileStream = fileSystem.GetFileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read, true))
            {
                var memoryStream = new MemoryStream();

                await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false);

                memoryStream.Position = 0;

                return Image.FromStream(memoryStream, true, false);
            }
        }
开发者ID:Ceten,项目名称:MediaBrowser,代码行数:13,代码来源:DynamicImageHelpers.cs

示例5: GetSingleImage

 private static Task<Stream> GetSingleImage(List<string> files, IFileSystem fileSystem)
 {
     return Task.FromResult<Stream>(fileSystem.GetFileStream(files[0], FileMode.Open, FileAccess.Read, FileShare.Read));
 }
开发者ID:Ceten,项目名称:MediaBrowser,代码行数:4,代码来源:DynamicImageHelpers.cs


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