本文整理汇总了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;
}