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


C# ISurface.LoadElementsFromStream方法代码示例

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


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

示例1: LoadGreenshotSurface

        /// <summary>
        /// Load a Greenshot surface
        /// </summary>
        /// <param name="fullPath"></param>
        /// <returns></returns>
        public static ISurface LoadGreenshotSurface(string fullPath, ISurface returnSurface)
        {
            if (string.IsNullOrEmpty(fullPath))
            {
                return null;
            }
            Image fileImage = null;
            LOG.InfoFormat("Loading image from file {0}", fullPath);
            // Fixed lock problem Bug #3431881
            using (Stream surfaceFileStream = File.OpenRead(fullPath))
            {
                // And fixed problem that the bitmap stream is disposed... by Cloning the image
                // This also ensures the bitmap is correctly created

                // We create a copy of the bitmap, so everything else can be disposed
                surfaceFileStream.Position = 0;
                using (Image tmpImage = Image.FromStream(surfaceFileStream, true, true))
                {
                    LOG.DebugFormat("Loaded {0} with Size {1}x{2} and PixelFormat {3}", fullPath, tmpImage.Width, tmpImage.Height, tmpImage.PixelFormat);
                    fileImage = ImageHelper.Clone(tmpImage);
                }
                // Start at -14 read "GreenshotXX.YY" (XX=Major, YY=Minor)
                const int markerSize = 14;
                surfaceFileStream.Seek(-markerSize, SeekOrigin.End);
                string greenshotMarker;
                using (StreamReader streamReader = new StreamReader(surfaceFileStream))
                {
                    greenshotMarker = streamReader.ReadToEnd();
                    if (greenshotMarker == null || !greenshotMarker.StartsWith("Greenshot"))
                    {
                        throw new ArgumentException(string.Format("{0} is not a Greenshot file!", fullPath));
                    }
                    LOG.InfoFormat("Greenshot file format: {0}", greenshotMarker);
                    const int filesizeLocation = 8 + markerSize;
                    surfaceFileStream.Seek(-filesizeLocation, SeekOrigin.End);
                    long bytesWritten = 0;
                    using (BinaryReader reader = new BinaryReader(surfaceFileStream))
                    {
                        bytesWritten = reader.ReadInt64();
                        surfaceFileStream.Seek(-(bytesWritten + filesizeLocation), SeekOrigin.End);
                        returnSurface.LoadElementsFromStream(surfaceFileStream);
                    }
                }
            }
            if (fileImage != null)
            {
                returnSurface.Image = fileImage;
                LOG.InfoFormat("Information about file {0}: {1}x{2}-{3} Resolution {4}x{5}", fullPath, fileImage.Width, fileImage.Height, fileImage.PixelFormat, fileImage.HorizontalResolution, fileImage.VerticalResolution);
            }
            return returnSurface;
        }
开发者ID:yoykiee,项目名称:ShareX,代码行数:56,代码来源:ImageOutput.cs


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