コード例 #1
0
        public ActionResult CreateEmbroidery(string img, int coefficient, int cellsCount, string colors, string symbols, string symbolColor, bool grid)
        {
            Color[] palette = this.ParseFromStringColors(colors);
                Color color = this.ParseFromStringColors(symbolColor).First<Color>();
                char[] chArray = null;
                if (symbols != "")
                {
                    chArray = this.ParseFromStringSymbols(symbols);
                }
                byte[] buffer = Convert.FromBase64String(img.Substring(img.IndexOf(',') + 1));
                Bitmap image = null;
                using (MemoryStream stream = new MemoryStream(buffer))
                {
                    Bitmap bitmap2 = new Bitmap(stream);
                    image = new Bitmap(bitmap2.Width, bitmap2.Height);
                    for (int i = 0; i < bitmap2.Height; i++)
                    {
                        for (int j = 0; j < bitmap2.Width; j++)
                        {
                            image.SetPixel(j, i, bitmap2.GetPixel(j, i));
                        }
                    }
                }

                EmbroideryCreatorServiceClient client = new EmbroideryCreatorServiceClient();
                GridType none = GridType.None;
                if (grid)
                {
                    none = GridType.SolidLine;
                }

                    Bitmap bitmap3 = client.GetEmbroidery(image, coefficient, cellsCount, palette, chArray, color, none);
                    using (MemoryStream stream2 = new MemoryStream())
                    {
                        bitmap3.Save(stream2, ImageFormat.Jpeg);
                        buffer = stream2.ToArray();
                    }
                    string str2 = Convert.ToBase64String(buffer);
                    JsonResult result = base.Json(new { imageString = str2 }, JsonRequestBehavior.AllowGet);
                    result.MaxJsonLength = 0x7fffffff;
                    return result;
        }
コード例 #2
0
        public ActionResult GetResolutions(int cells, string img)
        {
            byte[] buffer = Convert.FromBase64String(img.Substring(img.IndexOf(',') + 1));
                Dictionary<string, int> dictionary = new Dictionary<string, int>();
                using (MemoryStream stream = new MemoryStream(buffer))
                {
                    Bitmap image = new Bitmap(stream);

                    if (cells > image.Width) return Json(new { IsValidCells = false });
                    dictionary = new EmbroideryCreatorServiceClient().PossibleResolutions(image, cells, 3, 12);
                }
                List<SelectListItem> items = new List<SelectListItem>();
                foreach (KeyValuePair<string, int> pair in dictionary)
                {
                    SelectListItem item = new SelectListItem
                    {
                        Text = pair.Key,
                        Value = pair.Value.ToString()
                    };
                    items.Add(item);
                }
                return base.Json(new { Resolutions = new SelectList(items, "Value", "Text"), IsValidCells = true });
        }