public virtual void SetMdMini(Bitmap image, MdMiniImageType type, MemoryStream bitmapStream = null) { if (type == MdMiniImageType.Spine) { if (bitmapStream == null) { if (File.Exists(spinePath)) { File.Delete(spinePath); } using (var file = File.OpenWrite(spinePath)) using (var copy = new Bitmap(image)) copy.Save(file, ImageFormat.Png); } } using (var template = new SpineGen.Spine.Template <Bitmap>() { Image = GetMdMiniBitmap(bitmapStream), LogoArea = new Rectangle(type == MdMiniImageType.Front ? 31 : 1, 1, type == MdMiniImageType.Front ? 150 : 28, 214), LogoRotation = SpineGen.Drawing.Rotation.RotateNone, LogoHorizontalAlignment = SpineGen.Drawing.HorizontalAlignment.Middle, LogoVerticalAlignment = SpineGen.Drawing.VerticalAlignment.Middle, AspectRange = type == MdMiniImageType.Front ? 0.04 : 0.006 }) { template.Image.ClearRegion(template.LogoArea); using (var output = template.Process(new SystemDrawingBitmap(new Bitmap(image)))) { if (bitmapStream == null) { if (File.Exists(mdMiniIconPath)) { File.Delete(mdMiniIconPath); } } var bitmap = output.Bitmap; //Quantize(ref bitmap); template.Dispose(); if (bitmapStream == null) { using (var file = File.OpenWrite(mdMiniIconPath)) bitmap.Save(file, ImageFormat.Png); } else { bitmapStream.Seek(0, SeekOrigin.Begin); bitmapStream.SetLength(0); bitmap.Save(bitmapStream, ImageFormat.Png); bitmapStream.Seek(0, SeekOrigin.Begin); } } } }
public virtual void SetMdMini(string path, MdMiniImageType type, MemoryStream bitmapStream = null) { if (!File.Exists(path)) { throw new FileNotFoundException($"File Not Found: {path}"); } Bitmap image; using (var file = File.OpenRead(path)) image = new Bitmap(file); SetMdMini(image, type, bitmapStream); }