本文整理汇总了C#中IDocument.GetStream方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetStream方法的具体用法?C# IDocument.GetStream怎么用?C# IDocument.GetStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessImage
private Stream ProcessImage(IDocument input, ISupportedImageFormat format, ImageInstruction ins)
{
using (var imageFactory = new img.ImageFactory(preserveExifData: true))
{
// Load, resize, set the format and quality and save an image.
img.ImageFactory fac;
using (Stream stream = input.GetStream())
{
fac = imageFactory.Load(stream).Format(format);
}
if (ins.IsNeedResize)
{
if (ins.IsCropRequired)
{
var layer = new ResizeLayer(
size: ins.GetCropSize().Value,
anchorPosition: ins.GetAnchorPosition(),
resizeMode: ResizeMode.Crop
);
fac.Resize(layer);
}
else
{
fac.Resize(ins.GetCropSize().Value);
}
}
foreach (var f in ins.Filters)
{
fac.Filter(ins.GetMatrixFilter(f));
}
if (ins.Brightness.HasValue)
{
fac.Brightness(ins.Brightness.Value);
}
if (ins.Constraint.HasValue)
{
fac.Constrain(ins.Constraint.Value);
}
if (ins.Opacity.HasValue)
{
fac.Alpha(ins.Opacity.Value);
}
if (ins.Hue != null)
{
fac.Hue(ins.Hue.Degrees, ins.Hue.Rotate);
}
if (ins.Tint != null)
{
fac.Tint(ins.Tint.Value);
}
if (ins.Vignette != null)
{
fac.Vignette(ins.Vignette.Value);
}
if (ins.Saturation.HasValue)
{
fac.Saturation(ins.Saturation.Value);
}
if (ins.Contrast.HasValue)
{
fac.Contrast(ins.Contrast.Value);
}
var outputStream = new MemoryStream();
fac.Save(outputStream);
outputStream.Seek(0, SeekOrigin.Begin);
return outputStream;
}
}
示例2: Write
private IDocument Write(IDocument input, IExecutionContext context, FilePath outputPath)
{
IFile output = context.FileSystem.GetOutputFile(outputPath);
if (output != null)
{
using (Stream inputStream = input.GetStream())
{
if (_ignoreEmptyContent && inputStream.Length == 0)
{
return input;
}
if (!_onlyMetadata)
{
using (Stream outputStream = _append ? output.OpenAppend() : output.OpenWrite())
{
inputStream.CopyTo(outputStream);
}
}
}
Trace.Verbose($"{(_onlyMetadata ? "Set metadata for" : "Wrote")} file {output.Path.FullPath} from {input.SourceString()}");
FilePath relativePath = context.FileSystem.GetOutputPath().GetRelativePath(output.Path) ?? output.Path.FileName;
FilePath fileNameWithoutExtension = output.Path.FileNameWithoutExtension;
MetadataItems metadata = new MetadataItems
{
{ Keys.RelativeFilePath, relativePath },
{ Keys.RelativeFilePathBase, fileNameWithoutExtension == null
? null : relativePath.Directory.CombineFile(output.Path.FileNameWithoutExtension) },
{ Keys.RelativeFileDir, relativePath.Directory }
};
if (_onlyMetadata)
{
metadata.Add(Keys.WritePath, outputPath);
}
else
{
metadata.AddRange(new MetadataItems
{
{ Keys.DestinationFileBase, fileNameWithoutExtension },
{ Keys.DestinationFileExt, output.Path.Extension },
{ Keys.DestinationFileName, output.Path.FileName },
{ Keys.DestinationFileDir, output.Path.Directory },
{ Keys.DestinationFilePath, output.Path },
{ Keys.DestinationFilePathBase, fileNameWithoutExtension == null
? null : output.Path.Directory.CombineFile(output.Path.FileNameWithoutExtension) },
});
}
return _onlyMetadata
? context.GetDocument(input, metadata)
: context.GetDocument(input, output.OpenRead(), metadata);
}
return input;
}