jellyfin/Emby.Drawing.Net/DynamicImageHelpers.cs

111 lines
3.8 KiB
C#
Raw Normal View History

2016-03-27 14:11:27 -07:00
using System.Collections.Generic;
2015-04-08 08:45:30 -07:00
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
2016-10-25 12:02:04 -07:00
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
2015-04-08 08:45:30 -07:00
2016-11-11 10:33:10 -07:00
namespace Emby.Drawing.Net
2015-04-08 08:45:30 -07:00
{
public static class DynamicImageHelpers
{
public static void CreateThumbCollage(List<string> files,
IFileSystem fileSystem,
string file,
int width,
int height)
{
const int numStrips = 4;
2015-05-11 09:32:15 -07:00
files = ImageHelpers.ProjectPaths(files, numStrips);
2015-04-08 08:45:30 -07:00
const int rows = 1;
2015-05-11 09:32:15 -07:00
int cols = numStrips;
2015-04-08 08:45:30 -07:00
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;
2016-08-24 20:44:59 -07:00
2016-08-24 21:54:06 -07:00
// SourceCopy causes the image to be blank in OSX
2016-08-24 20:44:59 -07:00
//graphics.CompositingMode = CompositingMode.SourceCopy;
2015-04-08 08:45:30 -07:00
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)
{
2016-08-24 20:44:59 -07:00
using (var imgtemp = Image.FromFile(files[index]))
2015-04-08 08:45:30 -07:00
{
2016-08-24 20:44:59 -07:00
graphics.DrawImage(imgtemp, x, y, cellWidth, cellHeight);
2015-04-08 08:45:30 -07:00
}
}
index++;
}
}
img.Save(file);
}
}
}
public static void CreateSquareCollage(List<string> files,
IFileSystem fileSystem,
string file,
int width,
int height)
{
2015-05-11 09:32:15 -07:00
files = ImageHelpers.ProjectPaths(files, 4);
2015-04-08 08:45:30 -07:00
const int rows = 2;
const int cols = 2;
int singleSize = width / 2;
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;
2016-08-24 20:44:59 -07:00
2016-08-24 21:54:06 -07:00
// SourceCopy causes the image to be blank in OSX
2016-08-24 20:44:59 -07:00
//graphics.CompositingMode = CompositingMode.SourceCopy;
2015-04-08 08:45:30 -07:00
for (var row = 0; row < rows; row++)
{
for (var col = 0; col < cols; col++)
{
var x = col * singleSize;
var y = row * singleSize;
2016-08-24 20:44:59 -07:00
using (var imgtemp = Image.FromFile(files[index]))
2015-04-08 08:45:30 -07:00
{
2016-08-24 20:44:59 -07:00
graphics.DrawImage(imgtemp, x, y, singleSize, singleSize);
2015-04-08 08:45:30 -07:00
}
index++;
}
}
img.Save(file);
}
}
}
}
}