示例#1
0
        public static string Seed(DUETContext db)
        {
            string result = "";

            if (result == "")
            {
                result = Inspiration.Add(db, "GDansk", "img1.jpg");
            }
            if (result == "")
            {
                result = Inspiration.Add(db, "GDinia", "img2.jpg");
            }
            if (result == "")
            {
                result = Inspiration.Add(db, "Chicago", "img3.jpg");
            }
            if (result == "")
            {
                result = Inspiration.Add(db, "Miami", "img4.jpg");
            }
            //if (result == "")
            //{
            //    result = Inspiration.Add(db, "Bali", "img5.jpg");
            //}
            //if (result == "")
            //{
            //    result = Inspiration.Add(db, "Curacau", "img6.jpg");
            //}
            //if (result == "")
            //{
            //    result = Inspiration.Add(db, "Enschede", "img7.jpg");
            //}
            //if (result == "")
            //{
            //    result = Inspiration.Add(db, "Amsterdam", "img8.jpg");
            //}
            db.SaveChanges();
            return(result);
        }
示例#2
0
        public Stamp(DUETContext db, int Id, dynamic _stamp, dynamic _inspiration)
        {
            DesignId = Id;
            String title = _inspiration.title;

            InspirationId     = Inspiration.Get(db, title);
            X                 = _inspiration.x;
            Y                 = _inspiration.y;
            InspirationWidth  = _inspiration.width;
            InspirationHeight = _inspiration.height;
            Width             = _stamp.width;
            Height            = _stamp.height;
            int index = _stamp.shapeindex;

            Shape  = Stamp.GetShape(index);
            Type   = _stamp.type;
            Scale  = _stamp.scale;
            Rotate = _stamp.rotate;
            Red    = _stamp.r;
            Green  = _stamp.g;
            Blue   = _stamp.b;
            Used   = false;
        }
示例#3
0
        public static string Add(DUETContext db, string title, string src)
        {
            try
            {
                string path = App.ROOT + "images/big/" + src;
                using (var bitmap = new Bitmap(path)){
                    var inspiration = new Inspiration();
                    inspiration.Title  = title;
                    inspiration.Src    = "images/big/" + src;
                    inspiration.Width  = bitmap.Width;
                    inspiration.Height = bitmap.Height;
                    inspiration.DPIH   = bitmap.HorizontalResolution; //pixels per inch
                    inspiration.DPIV   = bitmap.VerticalResolution;   //pixels per inch

                    db.Inspirations.Add(inspiration);
                    db.SaveChanges();
                }
                return("");
            }
            catch (Exception exception) {
                return("Error: " + exception.Message);
            }
        }
示例#4
0
        public static string Delete(DUETContext db, int ID)
        {
            string result = "";

            try
            {
                Inspiration inspiration = db.Inspirations.FirstOrDefault(i => i.Id == ID);
                if (inspiration != null)
                {
                    db.Remove(inspiration);
                    db.SaveChanges();
                    return(result);
                }
                else
                {
                    return("Error: Inspiration " + ID + " not found.");
                }
            }
            catch (Exception exception)
            {
                return("Error: " + exception.Message);
            }
        }
示例#5
0
        public string CreateBitmap(DUETContext db, Design design)
        {
            try
            {
                Inspiration aInspiration = Inspiration.GetWithID(db, this.InspirationId);



                string path = App.ROOT + aInspiration.Src;


                // Create a Bitmap object from a file.
                using (Bitmap bitmapInspire = new Bitmap(path))
                {
                    bitmapInspire.SetResolution(96.0F, 96.0F);

                    Size viewstampsize = new Size((int)(Width), (int)(Height));
                    int  inspirex      = App.factor(X, this.InspirationWidth, bitmapInspire.Width);
                    int  inspirey      = App.factor(Y, this.InspirationHeight, bitmapInspire.Height);


                    int  inspirestampwidth  = App.factor((int)(Width), design.ViewWidth, design.Width);
                    int  inspirestampheight = App.factor((int)(Height), design.ViewWidth, design.Width); //make square
                    Size inspirestampsize   = new Size(inspirestampwidth, inspirestampheight);
                    inspirex = (int)(inspirex - (inspirestampwidth / 2));
                    inspirey = (int)(inspirey - (inspirestampheight / 2));



                    //get bitmap from inspire
                    if (inspirex < 0)
                    {
                        inspirex = 0;
                    }
                    if (inspirey < 0)
                    {
                        inspirey = 0;
                    }
                    if (inspirex > bitmapInspire.Width - inspirestampwidth)
                    {
                        inspirex = bitmapInspire.Width - inspirestampwidth;
                    }
                    if (inspirey > bitmapInspire.Height - inspirestampheight)
                    {
                        inspirey = bitmapInspire.Height - inspirestampheight;
                    }
                    Rectangle inspirestampRect = new Rectangle(inspirex, inspirey, (int)(inspirestampwidth), (int)(inspirestampheight));

                    using (var inspirestampBitmap = bitmapInspire.Clone(inspirestampRect, PixelFormat.Format32bppPArgb)){
                        byte[] inspireBytes = App.ImageToByte(inspirestampBitmap, inspirestampsize, ImageFormat.Bmp);


                        //Set filter with mask image
                        string maskpath = App.ROOT + "images/" + Shape;
                        using (Bitmap stampshape = new Bitmap(maskpath))
                        {
                            stampshape.SetResolution(96.0F, 96.0F);
                            using (var mask = App.ResizeImage(stampshape, inspirestampwidth, inspirestampheight))
                            {
                                byte[] maskBytes = App.ImageToByte(mask, inspirestampsize, ImageFormat.Bmp);

                                Color bgcolor    = Color.FromArgb(Red, Green, Blue);
                                float hue        = bgcolor.GetHue();
                                float saturation = bgcolor.GetSaturation();
                                float brightness = bgcolor.GetBrightness();
                                var   sumcolor   = bgcolor.R + bgcolor.G + bgcolor.B;

                                int start = maskBytes.Length - (inspirestampwidth * inspirestampheight * 4);
                                for (int i = start; i < maskBytes.Length; i += 4)
                                {
                                    if (maskBytes[i + 3] == 255)
                                    {
                                        maskBytes[i]     = 0;
                                        maskBytes[i + 1] = 0;
                                        maskBytes[i + 2] = 0;
                                        maskBytes[i + 3] = 255;
                                    }
                                    else
                                    {
                                        maskBytes[i]     = 255;
                                        maskBytes[i + 1] = 255;
                                        maskBytes[i + 2] = 255;
                                        maskBytes[i + 3] = 0;
                                    }
                                }
                                //in een bitmap wordt de array met kleuren van achteren naar voren opgebouwd dus het is elke keer B,G,R,A
                                if (Type == "copy")
                                {
                                    for (var i = start; i < maskBytes.Length; i += 4)
                                    {
                                        if (maskBytes[i + 3] < 255)
                                        {
                                            //transparant
                                            inspireBytes[i]     = 255;
                                            inspireBytes[i + 1] = 255;
                                            inspireBytes[i + 2] = 255;
                                            inspireBytes[i + 3] = 255;
                                        }
                                    }
                                }
                                else if (Type == "color")
                                {
                                    for (var i = start; i < maskBytes.Length; i += 4)
                                    {
                                        //if (maskBytes[i] == 255 && maskBytes[i + 1] == 255 && maskBytes[i + 2] == 255 && maskBytes[i + 3] == 0){
                                        if (maskBytes[i + 3] < 100)
                                        {
                                            //transparant
                                            inspireBytes[i]     = 255;
                                            inspireBytes[i + 1] = 255;
                                            inspireBytes[i + 2] = 255;
                                            inspireBytes[i + 3] = 255;
                                        }
                                        else
                                        {
                                            //color vergelijk color met bgcolor;
                                            Color acolor = Color.FromArgb(inspireBytes[i + 2], inspireBytes[i + 1], inspireBytes[i]);
                                            if (Math.Abs(acolor.GetHue() - hue) < 30)
                                            { //dezelfde kleur => verander niet
                                            }
                                            else
                                            {
                                                //maak wit => wit wordt transparant
                                                inspireBytes[i]     = 255;
                                                inspireBytes[i + 1] = 255;
                                                inspireBytes[i + 2] = 255;
                                                inspireBytes[i + 3] = 255;
                                            }
                                        }
                                    }
                                }
                                else if (Type == "lightness")
                                {
                                    for (var i = start; i < maskBytes.Length; i += 4)
                                    {
                                        //if (maskBytes[i] == 255 && maskBytes[i +1] == 255 && maskBytes[i + 2] == 255 && maskBytes[i + 3] == 0)
                                        if (maskBytes[i + 3] < 100)
                                        {
                                            //transparant
                                            inspireBytes[i]     = 255;
                                            inspireBytes[i + 1] = 255;
                                            inspireBytes[i + 2] = 255;
                                            inspireBytes[i + 3] = 255;
                                        }
                                        else
                                        {
                                            //lightness vergelijk sum met stamp.bgcolor sum;
                                            Color acolor = Color.FromArgb(inspireBytes[i + 2], inspireBytes[i + 1], inspireBytes[i]);
                                            if (Math.Abs(acolor.GetBrightness() - brightness) < 0.1)
                                            {
                                                //dezefde lightness => verander niets
                                            }
                                            else
                                            {
                                                inspireBytes[i]     = 255;
                                                inspireBytes[i + 1] = 255;
                                                inspireBytes[i + 2] = 255;
                                                inspireBytes[i + 3] = 255;
                                            }
                                        }
                                    }
                                }


                                //coversie van bytes[] naar memorystream naar bitmap
                                using (var ms = new MemoryStream(inspireBytes))
                                {
                                    Bitmap = new Bitmap(ms);
                                    Bitmap.MakeTransparent(Color.FromArgb(255, 255, 255));
                                    Bitmap.SetResolution(96.0F, 96.0F);

                                    //now create client site image
                                    using (var bitmap1 = App.ResizeImage(Bitmap, this.Width, this.Height)){
                                        bitmap1.MakeTransparent(Color.FromArgb(255, 255, 255));
                                        Byte[] bytes = App.ImageToByte(bitmap1, viewstampsize, ImageFormat.Png);
                                        //conversie van bytes naar dataurl
                                        return(Convert.ToBase64String(bytes));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                return("Error in stamp class: " + exception.Message);
            }
        }
示例#6
0
        public static int Get(DUETContext db, string title)
        {
            Inspiration aInspiration = db.Inspirations.SingleOrDefault(i => i.Title == title);

            return(aInspiration.Id);
        }