示例#1
0
        /********************END TEST******/
        public void Init(DUETContext db, dynamic _design)
        {
            MemberId   = Member.Id;
            Name       = "DUET";
            Width      = _design.width;
            Height     = _design.height;
            DPI        = App.DPI;
            ViewWidth  = _design.viewwidth;
            ViewHeight = _design.viewheight;
            Date       = DateTime.Now;
            Saved      = false;
            Shared     = false;
            Likes      = 0;
            Red        = 255;
            Green      = 255;
            Blue       = 255;
            Bgcolor    = Color.FromArgb(Red, Green, Blue);

            Processes    = new List <Proces>();
            Stamps       = new List <Stamp>();
            CurrentStamp = null;

            db.Update(this);
            db.SaveChanges();
        }
示例#2
0
        public Design(DUETContext db, Member Member, dynamic _design)
        {
            MemberId = Member.Id;
            Name     = "DUET";
            if (_design.width == null)
            {
                Width  = App.DESIGNWIDTH;
                Height = App.DESIGNHEIGHT;
            }
            else
            {
                Width  = _design.width;
                Height = _design.height;
            }
            DPI = App.DPI;

            ViewWidth  = _design.viewwidth;
            ViewHeight = _design.viewheight;

            Date = DateTime.Now;

            Saved  = false;
            Shared = false;
            Likes  = 0;
        }
示例#3
0
        public string Proces(DUETContext db, dynamic _proces)
        {
            try {
                var index = ((JArray)_proces.index).Select(i => (int)i).ToArray();
                var x     = ((JArray)_proces.x).Select(i => (int)i).ToArray();
                var y     = ((JArray)_proces.y).Select(i => (int)i).ToArray();

                if (x.Length > 0)
                {
                    if (CurrentStamp.Used == false)
                    {
                        CurrentStamp.Used = true;
                        db.Stamps.Update(CurrentStamp);
                        db.SaveChanges();
                    }
                    {
                        for (var i = 0; i < x.Length; i++)
                        {
                            int a     = App.factor(x[i], ViewWidth, Width);
                            int b     = App.factor(y[i], ViewHeight, Height); //square
                            int andex = index[i];

                            Proces proces = new Proces(Id, CurrentStamp.Id, a, b, andex);
                            Processes.Add(proces);
                        }
                        db.SaveChanges();
                    }
                }
                return("");
            }
            catch (Exception exception)
            {
                return("Error in Design Proces: " + exception.Message);
            }
        }
示例#4
0
        public static Bitmap GeneratePattern(DUETContext db, int id, int width, int height)
        {
            var design = db.Designs.SingleOrDefault(d => d.Id == id);

            if (design != null)
            {
                // Create a Bitmap object from a file.
                Bitmap pattern = new Bitmap(width, height);

                using (Bitmap bitmap = GenerateBitmap(db, id, width / 2, height / 2))
                {
                    Size size     = new Size(width, height);
                    Size halfsize = new Size(width / 2, height / 2);


                    using (Graphics GE = Graphics.FromImage(pattern))
                    {
                        Rectangle correct = new Rectangle(0, 0, halfsize.Width, halfsize.Height);

                        GE.DrawImage(bitmap, new Rectangle(0, 0, halfsize.Width, halfsize.Height), correct, GraphicsUnit.Pixel);
                        GE.DrawImage(bitmap, new Rectangle(halfsize.Width, 0, halfsize.Width, halfsize.Height), correct, GraphicsUnit.Pixel);
                        GE.DrawImage(bitmap, new Rectangle(halfsize.Width, halfsize.Height, halfsize.Width, halfsize.Height), correct, GraphicsUnit.Pixel);
                        GE.DrawImage(bitmap, new Rectangle(0, halfsize.Height, halfsize.Width, halfsize.Height), correct, GraphicsUnit.Pixel);

                        return(pattern);
                    }
                }
            }
            return(null);
        }
示例#5
0
 public void SetBackgroundColor(DUETContext db, int red, int green, int blue)
 {
     Red     = red;
     Green   = green;
     Blue    = blue;
     Bgcolor = Color.FromArgb(red, green, blue);
     db.Designs.Update(this);
     db.SaveChanges();
 }
示例#6
0
        public static void ResetProcessedDate(DUETContext db)
        {
            var orders = db.Orders.Where(o => o.Processed == false).ToArray();

            for (int i = 0; i < orders.Length; i++)
            {
                orders[i].ProcessedDate = orders[i].OrderDate.AddDays(App.PROCESDAYS);
            }
            db.Orders.UpdateRange(orders);
            db.SaveChanges();
        }
示例#7
0
 public string Save(DUETContext db)
 {
     try
     {
         db.Orders.Add(this);
         db.SaveChanges();
         return(GetNr());
     }
     catch (Exception exception)
     {
         return("Error: " + exception.Message);
     }
 }
示例#8
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);
        }
示例#9
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);
            }
        }
示例#10
0
 public String Save(DUETContext db)
 {
     try
     {
         db.Stamps.Add(this);
         db.SaveChanges();
         return("");
     }
     catch (Exception exception)
     {
         return("Error in Stamp Save: " + exception.Message);
     }
 }
示例#11
0
        public string CreateStamp(DUETContext db, dynamic _stamp, dynamic _inspiration)
        {
            try
            {
                CurrentStamp = new Stamp(db, Id, _stamp, _inspiration);
                CurrentStamp.Save(db);
                Stamps.Add(CurrentStamp);


                return(CurrentStamp.CreateBitmap(db, this));
            }
            catch (Exception exception)
            {
                return("Error 2: " + exception.Message);
            }
        }
示例#12
0
 public static string Share(DUETContext db, int id)
 {
     try
     {
         var adesign = db.Designs.SingleOrDefault(d => d.Id == id);
         if (adesign != null)
         {
             adesign.Shared = !adesign.Shared;
             db.Designs.Update(adesign);
             db.SaveChanges();
         }
         return("");
     }
     catch (Exception exception)
     {
         return("Error 18:" + exception.Message);
     }
 }
示例#13
0
 public static string MySharedDesigns(DUETContext db, int memberid)
 {
     try
     {
         var designs = db.Designs.Where(d => d.MemberId == memberid && d.Shared == true).OrderByDescending(d => d.Date).Select(d => new { d.Id, d.Name, d.Date, Owner = d.Member.Name }).ToArray();
         if (designs.Length == 0)
         {
             return("You did not share any designs yet!");
         }
         else
         {
             return(JsonConvert.SerializeObject(designs));
         }
     }
     catch (Exception exception)
     {
         return("Error 17:" + exception.Message);
     }
 }
示例#14
0
        public static string GetMyDesignsData(DUETContext db, Member Member)
        {
            try
            {
                var designs = db.Designs.Where(d => d.MemberId == Member.Id)
                              .Include(d => d.Processes)
                              .Include(d => d.Stamps).ToArray();
                if (designs != null)
                {
                    var designdata = new List <DesignData>();
                    for (var i = 0; i < designs.Length; i++)
                    {
                        DesignData adesign = new DesignData();

                        adesign.Id            = designs[i].Id;
                        adesign.Name          = designs[i].Name;
                        adesign.Width         = designs[i].Width;
                        adesign.Height        = designs[i].Height;
                        adesign.DPI           = designs[i].DPI;
                        adesign.Owner         = Member.Name;
                        adesign.Date          = designs[i].Date.ToShortDateString();
                        adesign.Shared        = designs[i].Shared;
                        adesign.Red           = designs[i].Red;
                        adesign.Blue          = designs[i].Blue;
                        adesign.Green         = designs[i].Green;
                        adesign.UsedStamps    = designs[i].Stamps.Count;
                        adesign.UsedStampings = designs[i].Processes.Count;

                        designdata.Add(adesign);
                    }

                    return(JsonConvert.SerializeObject(designdata));
                }
                else
                {
                    return("Error: No Design");
                }
            }
            catch (Exception exception)
            {
                return("Error 27:" + exception.Message);
            }
        }
示例#15
0
 public static string Delete(DUETContext db, int designID)
 {
     try
     {
         var stamps = db.Stamps.Where(s => s.DesignId == designID).ToArray();
         for (int s = 0; s < stamps.Length; s++)
         {
             if (stamps[s].Bitmap != null)
             {
                 stamps[s].Bitmap.Dispose();
             }
         }
         db.Stamps.RemoveRange(stamps);
         db.SaveChanges();
         return("");
     }
     catch (Exception exception) {
         return("Error in Stamp Class: " + exception.Message);
     }
 }
示例#16
0
 public static string DeleteDesign(DUETContext db, int designid)
 {
     try
     {
         var design = db.Designs.SingleOrDefault(d => d.Id == designid);
         if (design != null)
         {
             db.Designs.Remove(design);
             db.SaveChanges();
             return("");
         }
         else
         {
             return("");
         }
     }
     catch (Exception exception)
     {
         return("Error 4:" + exception.Message);
     }
 }
示例#17
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);
        }
示例#18
0
        public static string GetInfo(DUETContext db, int id)
        {
            try
            {
                string str = "";
                //var adesign = db.Designs.Select(d => new { d.ID, d.Name, d.PathToDesign, d.Date, Owner = d.member.Name , d.Width, d.Height}).SingleOrDefault(d => d.ID == id);
                var adesign = db.Designs.SingleOrDefault(d => d.Id == id);
                var astamps = db.Stamps.Where(d => d.DesignId == id).ToArray();
                ///change
                //var aprocesses = db.Processes.Where(d => d.designID == id).ToArray();
                if (adesign != null)
                {
                    adesign.Member = db.Members.SingleOrDefault(d => d.Id == adesign.MemberId);
                    str           += "<h3>" + adesign.Name + "-" + adesign.Id + "</h3>";
                    str           += "<img src='' />";
                    str           += "<p>";
                    str           += "created by:" + adesign.Member.Name + "</br>";
                    str           += "created on:" + adesign.Date + "</br>";
                    str           += "width: " + adesign.Width + "</br>";
                    str           += "height:" + adesign.Height + "</br>";
                    str           += "used stamps:" + astamps.Length + "</br>";
                    ///change
                    // str += "stampings:" + aprocesses.Length + "</br>";
                    str += "</p>";

                    return(str);
                }
                else
                {
                    str = id.ToString() + " not found.";
                    return(str);
                }
            }
            catch (Exception exception)
            {
                return("Error 18:" + exception.Message);
            }
        }
示例#19
0
        public static string GetDesignData(DUETContext db, int designid)
        {
            try
            {
                var design = db.Designs.Where(d => d.Id == designid)
                             .Include(d => d.Member)
                             .Include(d => d.Processes)
                             .Include(d => d.Stamps).First();
                if (design != null)
                {
                    DesignData adesign = new DesignData();

                    adesign.Id            = design.Id;
                    adesign.Name          = design.Name;
                    adesign.Width         = design.Width;
                    adesign.Height        = design.Height;
                    adesign.DPI           = design.DPI;
                    adesign.Owner         = design.Member.Name;
                    adesign.Date          = design.Date.ToShortDateString();
                    adesign.Shared        = design.Shared;
                    adesign.Red           = design.Red;
                    adesign.Blue          = design.Blue;
                    adesign.Green         = design.Green;
                    adesign.UsedStamps    = design.Stamps.Count;
                    adesign.UsedStampings = design.Processes.Count;

                    return(JsonConvert.SerializeObject(adesign));
                }
                else
                {
                    return("Error: No Design");
                }
            }
            catch (Exception exception)
            {
                return("Error 27:" + exception.Message);
            }
        }
示例#20
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;
        }
示例#21
0
        public string Save(DUETContext db, dynamic _design)
        {
            try
            {
                Width      = _design.width;
                Height     = _design.height;
                DPI        = App.DPI;
                ViewWidth  = _design.viewwidth;
                ViewHeight = _design.viewheight;
                Saved      = true;
                db.Designs.Update(this);
                //verwijder niet gebruikte stamps.
                var stamps = db.Stamps.Where(d => d.Used == false);
                db.Stamps.RemoveRange(stamps);
                db.SaveChanges();

                return("");
            }
            catch (Exception exception)
            {
                return("Error: " + exception.Message);
            }
        }
示例#22
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);
            }
        }
示例#23
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);
            }
        }
示例#24
0
        public string CopyDesign(DUETContext db, int designid)
        {
            try
            {
                if (Saved == false)
                {
                    var copydesign = db.Designs.Where(d => d.Id == designid)
                                     .Include(d => d.Member)
                                     .Include(d => d.Processes)
                                     .ThenInclude(p => p.Stamp).First();

                    if (copydesign == null)
                    {
                        return("Error in Design Copy: No design found to copy.");
                    }
                    else
                    {
                        Width  = copydesign.Width;
                        Height = copydesign.Height;

                        Red   = copydesign.Red;
                        Green = copydesign.Green;
                        Blue  = copydesign.Blue;

                        Processes = new List <Proces>();
                        Stamps    = new List <Stamp>();
                        //db.Designs.Update(this);
                        var laststampid = -1;

                        foreach (var copyProces in copydesign.Processes)
                        {
                            Proces proces = new Proces();
                            proces.DesignId = Id;
                            proces.Index    = copyProces.Index;
                            proces.X        = copyProces.X;
                            proces.Y        = copyProces.Y;

                            if (copyProces.StampId != laststampid)
                            {
                                var stamp = new Stamp();
                                stamp.DesignId          = Id;
                                stamp.InspirationId     = copyProces.Stamp.InspirationId;
                                stamp.InspirationWidth  = copyProces.Stamp.InspirationWidth;
                                stamp.InspirationHeight = copyProces.Stamp.InspirationHeight;
                                stamp.Width             = copyProces.Stamp.Width;
                                stamp.Height            = copyProces.Stamp.Height;
                                stamp.X      = copyProces.Stamp.X;
                                stamp.Y      = copyProces.Stamp.Y;
                                stamp.Type   = copyProces.Stamp.Type;
                                stamp.Shape  = copyProces.Stamp.Shape;
                                stamp.Scale  = copyProces.Stamp.Scale;
                                stamp.Rotate = copyProces.Stamp.Rotate;
                                stamp.Red    = copyProces.Stamp.Red;
                                stamp.Green  = copyProces.Stamp.Green;
                                stamp.Blue   = copyProces.Stamp.Blue;
                                stamp.Used   = true;

                                Stamps.Add(stamp);
                                db.Stamps.Add(stamp);
                                db.SaveChanges(); // deze moet anders heb je geen stampId in je proces

                                laststampid = copyProces.StampId;
                            }
                            proces.StampId = laststampid;
                            db.Processes.Add(proces);
                        }

                        db.SaveChanges();
                    }
                    return(GetDesignData(db, designid));
                }
                else
                {
                    return("Error in Design Copy: Your design is already saved. First create a new Design.");
                }
            }
            catch (Exception exception)
            {
                return("Error in Design Copy: " + exception.Message);
            }
        }
示例#25
0
 public static Inspiration GetWithID(DUETContext db, int ID)
 {
     return(db.Inspirations.SingleOrDefault(i => i.Id == ID));
 }
示例#26
0
        public static int Get(DUETContext db, string title)
        {
            Inspiration aInspiration = db.Inspirations.SingleOrDefault(i => i.Title == title);

            return(aInspiration.Id);
        }
示例#27
0
        //public static string GetDesignData(DUETContext db,  int id)
        //{
        //    try
        //    {
        //        var adesign = db.Designs.SingleOrDefault(d => d.Id == id);
        //        if (adesign != null)
        //        {
        //            var designdata = new DesignData
        //            {
        //                Id = id,
        //                Width = adesign.Width,
        //                Height = adesign.Height,
        //                Owner =adesign.Member.Name,
        //                Date = adesign.Date.ToShortDateString(),
        //                Shared = adesign.Shared,
        //                Red = adesign.Red,
        //                Blue = adesign.Blue,
        //                Green = adesign.Green,
        //                UsedStamps = adesign.Stamps.Count,
        //                UsedStampings = adesign.Processes.Count
        //            };
        //            return JsonConvert.SerializeObject(designdata);
        //        }
        //        else
        //        {
        //            return "Error: No Design";
        //        }

        //    }
        //    catch (Exception exception)
        //    {
        //        return "Error 27:" + exception.Message;
        //    }
        //}
        public static Bitmap GenerateBitmap(DUETContext db, int id, int genwidth, int genheight)
        {
            try
            {
                var adesign = db.Designs.Where(d => d.Id == id)
                              .Include(d => d.Processes)
                              .ThenInclude(p => p.Stamp)
                              .First();


                var factor = (genwidth * 1.0) / adesign.Width;

                Bitmap designbitmap = new Bitmap(genwidth, genheight, PixelFormat.Format32bppArgb);

                if (adesign.Processes.Count > 0)
                {
                    using (Graphics GE = Graphics.FromImage(designbitmap))
                    {
                        GE.CompositingMode = CompositingMode.SourceOver;
                        float[][]   matrixItems = { new float[] { 1, 0, 0, 0, 0 },
                                                    new float[]   { 0, 1, 0, 0, 0 },
                                                    new float[]   { 0, 0, 1, 0, 0 },
                                                    new float[]   { 0, 0, 0, 1, 0 },
                                                    new float[]   { 0, 0, 0, 0, 1 } };
                        ColorMatrix colorMatrix = new ColorMatrix(matrixItems);

                        ImageAttributes imageAtt = new ImageAttributes();
                        imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                        //Set backgroundcolor
                        using (SolidBrush brush = new SolidBrush(Color.FromArgb(adesign.Red, adesign.Green, adesign.Blue)))
                        {
                            Rectangle rectangle = new Rectangle(0, 0, adesign.Width, adesign.Height);
                            GE.FillRectangle(brush, rectangle);
                        }

                        ////doorloop alle processes

                        Bitmap bstamp      = null;
                        int    laststampid = -1;
                        foreach (var proces in adesign.Processes)
                        {
                            if (proces.StampId != laststampid)
                            {
                                proces.Stamp.CreateBitmap(db, adesign);
                                laststampid = proces.StampId;
                                Size size = new Size((int)(proces.Stamp.Bitmap.Width * factor), (int)(proces.Stamp.Bitmap.Height * factor));
                                bstamp = new Bitmap(proces.Stamp.Bitmap, size);
                            }
                            if (bstamp != null)
                            {
                                int w  = bstamp.Width;
                                int h  = bstamp.Height;
                                int tx = (int)((proces.X * factor) + (w / 2 * proces.Stamp.Scale));
                                int ty = (int)((proces.Y * factor) + (h / 2 * proces.Stamp.Scale));

                                if (proces.Stamp.Rotate > 0)
                                {
                                    Rectangle designrect = new Rectangle((int)(-w / 2 * proces.Stamp.Scale), (int)(-h / 2 * proces.Stamp.Scale), (int)(w * proces.Stamp.Scale), (int)(h * proces.Stamp.Scale));

                                    GE.TranslateTransform(tx, ty);
                                    GE.RotateTransform(proces.Stamp.Rotate);
                                    GE.DrawImage(bstamp, designrect, 0, 0, bstamp.Width, bstamp.Height, GraphicsUnit.Pixel, imageAtt);
                                    GE.ResetTransform();
                                }
                                else
                                {
                                    Rectangle designrect = new Rectangle((int)(proces.X * factor), (int)(proces.Y * factor), (int)(w * proces.Stamp.Scale), (int)(h * proces.Stamp.Scale));
                                    GE.DrawImage(bstamp, designrect, 0, 0, bstamp.Width, bstamp.Height, GraphicsUnit.Pixel, imageAtt);
                                }
                            }
                        }
                        //astamp.Bitmap.Dispose();
                        //bstamp.Dispose();
                    }
                }
                return(designbitmap);
            }
            catch (Exception exception)
            {
                Console.Write("Error in Generate Bitmap:" + exception.Message);
                return(null);
            }
        }
示例#28
0
 public TestController(DUET.Models.DUETContext context)
 {
     _context = context;
 }
示例#29
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);
            }
        }
示例#30
0
 public MemberController(DUET.Models.DUETContext context)
 {
     _context = context;
 }