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