Exemplo n.º 1
0
        public static Design GetOpenOrNewDesign(DUETContext db, Member member, dynamic _design)
        {
            Design aDesign = db.Designs.LastOrDefault(d => d.MemberId == member.Id && d.Saved == false);

            if (aDesign == null)
            {
                aDesign = new Design(db, member, _design);
                db.Designs.Add(aDesign);
                db.SaveChanges();
            }

            return(aDesign);
        }
Exemplo n.º 2
0
        /********************TEST******/
        public static string TestGetDesigns(DUETContext db, int id)
        {
            try
            {
                Design adesign = db.Designs.Include(d => d.Member).First();

                return(adesign.Member.Name);
            }
            catch (Exception exception)
            {
                return("Error: " + exception);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
 public Order(Member _member, Design _design)
 {
     MemberId  = _member.Id;
     DesignId  = _design.Id;
     OrderDate = DateTime.Now;
 }