Пример #1
0
        public void Photo()
        {
            var httpRequest = HttpContext.Current.Request;

            var file = httpRequest.Files[0];

            if (file != null && file.ContentLength > 0)
            {
                int MaxContentLength = 1024 * 1024 * 1; //Size = 1 MB

                IList <string> AllowedFileExtensions = new List <string> {
                    ".jpg", ".gif", ".png"
                };
                var ext       = file.FileName.Substring(file.FileName.LastIndexOf('.'));
                var extension = ext.ToLower();

                if (!AllowedFileExtensions.Contains(extension))
                {
                    var message = string.Format("Please Upload image of type .jpg,.gif,.png.");
                }
                else if (file.ContentLength > MaxContentLength)
                {
                    var message = string.Format("Please Upload a file upto 1 mb.");
                }
                else
                {
                    LovNaZaklad_WebAPI.EmguCV.ImageComparer imgCompare = new EmguCV.ImageComparer();
                    float[] features = imgCompare.features(file.InputStream);
                }
            }
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "TreasureID,Name,LocationID")] Treasure image)
        {
            // since we can uplaod just one file, we get the first one
            var file = Request.Files[0];
            // save images in server root in treasures dir
            var filePath = file.FileName;
            var fullPath = Server.MapPath("~/treasures/") + file.FileName;

            LovNaZaklad_WebAPI.EmguCV.ImageComparer imgCompare = new EmguCV.ImageComparer();
            float[] features = imgCompare.features(file.InputStream);

            // save features to database
            if (ModelState.IsValid)
            {
                db.Treasures.Add(new Treasure
                {
                    Name  = image.Name,
                    Image = new Image
                    {
                        Path     = filePath,
                        Features = string.Join(" ", features)
                    },
                    LocationID = image.LocationID
                });
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "Name", image.LocationID);
            return(View(image));
        }