NadekoBot/NadekoBot/Classes/ImageHandler.cs
Kwoth 485783d146 Using the newest discord.net , fixes, improvements
If you draw 5 cards now, you get a hand value.
2015-12-10 21:35:34 +01:00

48 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
namespace NadekoBot
{
class ImageHandler
{
/// <summary>
/// Merges Images into 1 Image and returns a bitmap.
/// </summary>
/// <param name="images">The Images you want to merge.</param>
/// <returns>Merged bitmap</returns>
public static Bitmap MergeImages(IEnumerable<Image> images)
{
if (images.Count() == 0) return null;
int width = images.Sum(i => i.Width);
int height = images.First().Height;
Bitmap bitmap = new Bitmap(width, height);
var r = new Random();
int offsetx = 0;
foreach (var img in images)
{
Bitmap bm = new Bitmap(img);
for (int w = 0; w < img.Width; w++)
{
for (int h = 0; h < img.Height; h++)
{
bitmap.SetPixel(w + offsetx, h, bm.GetPixel(w, h));
}
}
offsetx += img.Width;
}
return bitmap;
}
public static Stream ImageToStream(Image img,ImageFormat format) {
MemoryStream stream = new MemoryStream();
img.Save(stream, format);
stream.Position = 0;
return stream;
}
}
}