﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace meticulus.drawing
{
    public class Draw
    {
        public static Image ImageOnImageCentered(Image bottom, Image top)
        {
            Bitmap bmp = new Bitmap(bottom);
            Graphics g = Graphics.FromImage(bmp);
            g.DrawImage(top,ObjectPlacement.CenterObject(bottom.Size,top.Size));
            g.Save();
            return bmp;
            
        }
        public static Image ResizeImage(Image img, Size size)
        {
            return((Bitmap)img).GetThumbnailImage
                (size.Width, size.Height, new Image.GetThumbnailImageAbort(thumbnailabort), IntPtr.Zero);

        }
        private static bool thumbnailabort()
        {
            return false;
        }
        public static Image FadeImage(Image img, int alphavalue)
        {
            Bitmap bmp = new Bitmap(img);
            Graphics g = Graphics.FromImage(bmp);
            Brush b = new SolidBrush(Color.FromArgb(alphavalue,0,0,0));
            g.FillRectangle(b,0,0,img.Width,img.Height);
            g.Save();
            return bmp;
        }
        public static Image DrawRectangleonImage(Image img,int alphavalue, Color c,Rectangle r)
        {
            Bitmap bmp = new Bitmap(img);
            Graphics g = Graphics.FromImage(bmp);
            Brush b = new SolidBrush(Color.FromArgb(alphavalue, c));
            g.FillRectangle(b, r);
            g.Save();
            return bmp;
        }
        public static Image DrawTimeStampOnImage(Image img)
        {
            Graphics g = Graphics.FromImage(img);
            g.DrawString(DateTime.Now.ToString(),
                new Font(FontFamily.GenericSansSerif,8F),
                Brushes.Red,new PointF(0,0));
            g.Save();
            return img;
        }
        public static Image DrawString(Image img, String s, Point position)
        {
            Graphics g = Graphics.FromImage(img);
            g.DrawString(s,
                new Font(FontFamily.GenericSansSerif,8F),
                Brushes.Red,new PointF(position.X,position.Y));
            g.Save();
            return img;
        }
    }
}
