High performing Bitmap Drawing solution in c#
I have a use case where I need to render a collage of bitmaps as a
preview. The application is implemented as a MVC based REST service, and I
have a fairly vanilla implementation:
using (var bitmap = new Bitmap((int)maxWidth, (int)maxHeight))
{
using (var graphic = Graphics.FromImage(bitmap))
{
graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
// now again for each mod
foreach (var mod in mods)
{
var frame = frames.First(f => f.Index == mod.FrameIndex);
var fileInfo = GetFileInfo(mod);
using (var modImage = Image.FromFile(fileInfo.FullName))
{
graphic.DrawImage(modImage, (int)frame.Left, (int)frame.Top);
}
}
bitmap.Save(previewFileName);
}
}
While this code works fine, it performs very poorly (especially with
larger images). I am open to using third party libraries as well, I just
need a faster performing solution.
Any help would be mostly appreciated.
No comments:
Post a Comment