Example #1
0
        public static Models.ImageProfile SeedDefaultImageProfile(Models.Image image)
        {
            var imageProfile = new Models.ImageProfile();

            imageProfile.Kernel              = Settings.DefaultKernel32;
            imageProfile.BootImage           = "initrd.xz";
            imageProfile.Name                = "default";
            imageProfile.Description         = "Auto Generated Via New Image.";
            imageProfile.SkipCore            = 0;
            imageProfile.SkipClock           = 0;
            imageProfile.RemoveGPT           = 0;
            imageProfile.SkipShrinkVolumes   = 0;
            imageProfile.SkipShrinkLvm       = 0;
            imageProfile.SkipExpandVolumes   = 0;
            imageProfile.FixBcd              = 0;
            imageProfile.FixBootloader       = 1;
            imageProfile.PartitionMethod     = "Dynamic";
            imageProfile.Compression         = "lz4";
            imageProfile.CompressionLevel    = "1";
            imageProfile.TaskCompletedAction = "Reboot";
            imageProfile.ChangeName          = 1;
            if (image.Environment == "macOS")
            {
                imageProfile.OsxTargetVolume = "Macintosh HD";
            }

            return(imageProfile);
        }
Example #2
0
        /// <summary>
        /// Rotates the image when posted from mobile (mobile pictures were showing up sideways on computers)
        /// </summary>
        /// <param name="image">The image model containing the image file from HttpPostedFiledBase class</param>
        /// <returns>The properly rotated image as a System.Drawing.Image</returns>
        public System.Drawing.Image ImageRotation(Models.Image image)
        {
            System.Drawing.Image originalImage = System.Drawing.Image.FromStream(image.ImageFile.InputStream, true, true);

            if (originalImage.PropertyIdList.Contains(0x0112))
            {
                int rotationValue = originalImage.GetPropertyItem(0x0112).Value[0];
                switch (rotationValue)
                {
                case 1:     // landscape, do nothing
                    break;

                case 8:     // rotated 90 right
                            // de-rotate:
                    originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate270FlipNone);
                    break;

                case 3:     // bottoms up
                    originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate180FlipNone);
                    break;

                case 6:     // rotated 90 left
                    originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate90FlipNone);
                    break;
                }
            }

            return(originalImage);
        }
Example #3
0
        // GET: api/Files
        public async Task <IHttpActionResult> Get(string filename, FileType filetype, ImageExtension?extension)
        {
            if (filetype == FileType.ImageFile)
            {
                Models.Image imgModel = await db.Image.FirstOrDefaultAsync(fs => fs.File1.Path == filename);

                if (imgModel == null)
                {
                    return(NotFound());
                }

                string basePath = GetPartialDirectory(filetype);
                string path     = $"{basePath}{filename}";

                if (!System.IO.File.Exists(path))
                {
                    return(NotFound());
                }
                FileStream           flStream = new FileStream(path, FileMode.Open, FileAccess.Read);
                System.Drawing.Image img      = System.Drawing.Image.FromStream(flStream);

                MemoryStream ms = new MemoryStream();
                img.Save(ms, GetFormat(extension.Value));
                HttpResponseMessage message = new HttpResponseMessage
                {
                    Content = new ByteArrayContent(ms.ToArray())
                };
                message.Content.Headers.ContentType = new MediaTypeHeaderValue($"image/{extension}");
                return(ResponseMessage(message));
            }
            if (true)
            {
            }
            return(NotFound());
        }
        public IActionResult UploadImage(IList <IFormFile> files)
        {
            IFormFile uploadedImage = files.FirstOrDefault();

            if (uploadedImage == null || uploadedImage.ContentType.ToLower().StartsWith("image/"))
            {
                using (ImageDBContext dbContext = new ImageDBContext())
                {
                    MemoryStream ms = new MemoryStream();
                    uploadedImage.OpenReadStream().CopyTo(ms);

                    System.Drawing.Image image = System.Drawing.Image.FromStream(ms);

                    Models.Image imageEntity = new Models.Image()
                    {
                        Id          = Guid.NewGuid(),
                        Name        = uploadedImage.Name,
                        Data        = ms.ToArray(),
                        Width       = image.Width,
                        Height      = image.Height,
                        ContentType = uploadedImage.ContentType
                    };

                    dbContext.Images.Add(imageEntity);

                    dbContext.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Example #5
0
 public byte[] GetContentBytes(FrontContext context, Models.Image image)
 {
     if (image.ContentBytes == null)
     {
         var sitedb = context.RenderContext.WebSite.SiteDb();
     }
     return(image.ContentBytes);
 }
Example #6
0
        public async Task GetImageAsync()
        {
            Image = await _imageService.GetRandomImageAsync();

            var image = new BitmapImage(new Uri(Path.Combine(Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName), "images", Image.Filename), UriKind.Absolute));

            MainWindow._image.Source = image;
        }
        public IActionResult ViewImage(string Name)
        {
            Models.Image image = _Context.Image.FirstOrDefault(m => m.Name == Name);

            MemoryStream ms = new MemoryStream(image.Data);

            return(new FileStreamResult(ms, image.ContentType));
        }
        public FileStreamResult ViewImage(Guid id)
        {
            Models.Image image = _context.Images.FirstOrDefault(m => m.Id == id);

            MemoryStream ms = new MemoryStream(image.Data);

            return(new FileStreamResult(ms, image.ContentType));
        }
        private static MobileServiceFile GetFileReference(Models.Image image, string param)
        {
            var toDownload = new MobileServiceFile(image.File.Id, image.File.Name, image.File.TableName, image.File.ParentId)
            {
                StoreUri = image.File.StoreUri.Replace("lg", param)
            };

            return(toDownload);
        }
Example #10
0
 public string GetHtml(Models.Image image, string rel = null)
 {
     return("<a href=\"" + imageService.GetImageSrc(image) + "\" target=\"_blank\" class=\"colorbox\"" +
            (rel != null ? " rel=\"" + rel + "\"" : "") + ">" +
            "<img src=\"" + imageService.GetThumbnailSrc(image) + "\" " +
            "width=\"" + imageService.GetImageThumbnailWidth(image) + "\" " +
            "height=\"" + imageService.GetImageThumbnailHeight(image) + "\">" +
            "</a>");
 }
Example #11
0
 public PosterizeWindow(Models.Image img, ImageWindow parentWindow)
 {
     InitializeComponent();
     this.img          = img;
     this.parentWindow = parentWindow;
     prev_image        = new Models.Image();
     CloneOrginalImage();
     preview_image.Source = Utils.BitmapToImageSource(prev_image.Bitmap);
 }
Example #12
0
        /// <summary>
        /// generate an Image object based on the photo given.
        /// </summary>
        /// <param name="file">a photo file</param>
        /// <param name="year">the year that photo was taken</param>
        /// <param name="month">the month that photo was taken</param>
        /// <returns>an Image object representing the photo file given</returns>
        public Models.Image GeneratePhoto(FileInfo file, string year, string month)
        {
            string nameInWeb     = GenerateUniqName(file.Name, file.Name, 1);
            string relPathInProj = relThumbnsPath + "\\" + nameInWeb;

            Models.Image im = new Models.Image(file.Name, year, month, relPathInProj, file.FullName);
            im.NameInWeb = nameInWeb;
            return(im);
        }
Example #13
0
        //To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            Models.Image image = new Models.Image();

            ////Unique filename
            var uniqueFileName = Guid.NewGuid().ToString();
            var fileName       = Path.GetFileName(uniqueFileName + "." + Upload.FileName.Split(".")[1].ToLower());


            if (image.Data == null)
            {
                image.Data = new byte[Upload.Length + 1];
            }

            using (var memoryStream = new MemoryStream((int)Upload.Length))
            {
                await Upload.CopyToAsync(memoryStream);

                image.Data = memoryStream.ToArray();
            }


            if (Product.Images == null)
            {
                Product.Images = new List <Models.Image>();
            }

            Product.Images.Add(image);

            if (Product.ProductImage == null)
            {
                Product.ProductImage = 0;
            }


            image.ImageName = fileName;

            image.Product = Product;

            if (Product.ProductImage == null)
            {
                Product.ProductImage = 0;
            }

            if (Product.Images == null)
            {
                Product.Images = new List <Models.Image>();
            }

            string byte64 = Convert.ToBase64String(image.Data);

            image.Product = Product;


            return(RedirectToPage("./Index"));
        }
Example #14
0
        //public static void Render(FrontContext context)
        //{
        //    var image = context.SiteDb.ImagePool.Get(context.Route.objectId);

        //    if (image == null || image.ContentBytes == null)
        //    {
        //        image = context.SiteDb.Images.Get(context.Route.objectId);
        //    }
        //    if (context.RenderContext.WebSite.EnableImageLog)
        //    {
        //        if (context.RenderContext.Request.Channel == Data.Context.RequestChannel.Default)
        //        {
        //            Kooboo.Data.Models.ImageLog log = new Data.Models.ImageLog();
        //            log.ClientIP = context.RenderContext.Request.IP;
        //            log.Url = context.RenderContext.Request.RawRelativeUrl;
        //            log.StartTime = DateTime.Now;

        //            if (image != null)
        //            {
        //                log.Size = image.Size;
        //                log.ImageId = image.Id;
        //            }
        //            context.RenderContext.WebSite.SiteDb().ImageLog.Add(log);
        //        }
        //    }

        //    if (image == null)
        //    {
        //        return;
        //    }
        //    RenderImage(context, image);
        //}

        public static void RenderImage(FrontContext context, Models.Image image)
        {
            context.RenderContext.Response.ContentType = "image";

            if (Kooboo.Lib.Helper.UrlHelper.GetFileType(image.Extension) == Lib.Helper.UrlHelper.UrlFileType.Image)
            {
                string imagetype = image.Extension;
                if (imagetype.StartsWith("."))
                {
                    imagetype = imagetype.Substring(1);
                }
                context.RenderContext.Response.ContentType = context.RenderContext.Response.ContentType + "/" + imagetype;
            }

            //"image/svg+xml"
            if (image.Extension == "svg" || image.Extension == ".svg")
            {
                context.RenderContext.Response.ContentType += "+xml";
            }

            var bytes = image.ContentBytes;

            var width = context.RenderContext.Request.Get("width");

            if (!string.IsNullOrEmpty(width))
            {
                var height = context.RenderContext.Request.Get("height");

                if (!string.IsNullOrWhiteSpace(height))
                {
                    int intwidth  = 0;
                    int intheight = 0;
                    if (int.TryParse(width, out intwidth) && int.TryParse(height, out intheight))
                    {
                        bytes = GetImageThumbnail(context.RenderContext, bytes, intwidth, intheight, image.Version);
                    }
                }
                else
                {
                    int intwidth = 0;

                    if (int.TryParse(width, out intwidth))
                    {
                        if (image.Height > 0 && image.Width > 0)
                        {
                            int intheight = (int)intwidth * image.Height / image.Width;

                            bytes = GetImageThumbnail(context.RenderContext, bytes, intwidth, intheight, image.Version);
                        }
                    }
                }
            }


            context.RenderContext.Response.Body = bytes;
        }
Example #15
0
        /// <summary>
        /// Saves a System.Drawing.Image to the specified path and all data relating to an image to the database as a new record
        /// </summary>
        /// <param name="imageModel">The image model of data for the database</param>
        /// <param name="fileName">The specified path to save the image</param>
        public void SaveImage(Models.Image imageModel, string fileName)
        {
            System.Drawing.Image image = ImageRotation(imageModel);
            image.Save(fileName);
            UserServices service = new UserServices();

            imageModel.UserId = service.GetUser().UserId;
            db.Images.Add(imageModel);
            db.SaveChanges();
        }
Example #16
0
        public ActionResult View(int id)
        {
            Image imageModel = new Models.Image();

            using (Entities db = new Entities())
            {
                imageModel = db.Image.Where(x => x.Id == id).FirstOrDefault();
            }
            return(View(imageModel));
        }
Example #17
0
        public ImageDetailsViewModel(MobileServiceClient client, Models.Image image)
        {
            _client    = client;
            this.Image = image;

            this.OpenImageCommand = new Command <ImageSource>((source) =>
            {
                Device.OpenUri((Uri)source.GetValue(UriImageSource.UriProperty));
            });
        }
        public IActionResult PostImage([FromBody] Models.Image img)
        {
            if (img == null)
            {
                return(BadRequest());
            }
            var res = _mnistService.Calculate(img.Bytes.ToArray());

            return(Ok(res));
        }
Example #19
0
 /// <summary>
 /// displays the photo (in thumbnail size) that is going to be deleted, and
 /// wait to user's confirmation to delete it.
 /// </summary>
 /// <param name="srcPath"a photo to delete></param>
 /// <returns>DeletePhoto page view</returns>
 public ActionResult DeletePhoto(string srcPath)
 {
     Models.Image im = photosModel.Photos.Find(photo => photo.SrcPath == srcPath);
     if (im != null)
     {
         photosModel.PhotoToDelete = im;
         ViewBag.PhotoPathToDelete = im.Path;
     }
     return(View(im));
 }
Example #20
0
 public void AddView(int image_id)
 {
     using (MultimediaEntities db = new MultimediaEntities())
     {
         Models.Image f_image = db.Images.Where(x => x.FileID == image_id).First();
         f_image.ImageViews++;
         db.Entry(f_image).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Example #21
0
        private void SaveToDiskDbAndTweet(byte[] bytes)
        {
            string fileName = this.GetFileName();

            File.WriteAllBytes(fileName, bytes);
            System.Diagnostics.Debug.WriteLine("Wrote file: " + fileName);

            int imageID;

            using (var db = new Models.Database())
            {
                var robot = db.Robots.FirstOrDefault(l => l.ID == this.ROBOT_ID);

                var image = new Models.Image()
                {
                    iRobot        = robot,
                    FileDirectory = fileName,
                    TimeAdded     = DateTime.UtcNow,
                    TimeCreated   = DateTime.UtcNow,
                    TimeTaken     = DateTime.UtcNow
                };

                db.Images.Add(image);

                db.SaveChanges();
                imageID = image.ID;
            }

            System.Diagnostics.Debug.WriteLine("Saved Image to db with ID: " + imageID);

            string TweetText = string.Empty;

            //get stuffs from markov factory
            try
            {
                TweetText = Helpers.Markov.GetNextTwitterPictureMarkov();
            }
            catch (Exception e)
            {
                TweetText = "Wasn't able to generate Markov.";
                System.Diagnostics.Debug.WriteLine("Generating Markov threw an error.");
                Handlers.ExceptionLogger.LogException(e, Models.Fault.Server);
            }

            Helpers.FileOperations.ImageOperations.ApplyTextToImage(TweetText, fileName);

            try
            {
                Helpers.Twitter.PostTweetWithImage(this.ROBOT_ID, imageID, TweetText);
            }
            catch (Exception e)
            {
                Handlers.ExceptionLogger.LogException(e, Models.Fault.Server);
            }
        }
 public ImageWindow(MainWindow mainWindow, Models.Image img, Models.Application app)
 {
     InitializeComponent();
     this.img = img;
     this.app = app;
     this.mainWindow = mainWindow;
     Title = img.filename;
     imageControl.Source = Utils.BitmapToImageSource(img.Bitmap);
     Height = Width * img.Height / img.Width + 45;
     Show();
 }
Example #23
0
        public static int SubirImagen(HttpPostedFileBase image1)
        {
            EntityModel db = new EntityModel();

            Models.Image img = new Models.Image();
            img.ImageData = new byte[image1.ContentLength];
            image1.InputStream.Read(img.ImageData, 0, image1.ContentLength);
            db.Images.Add(img);
            db.SaveChanges();
            return(IdImagenSubida(img));
        }
Example #24
0
        /// <summary>
        /// displays the photo (in full size) that the user chose to view
        /// </summary>
        /// <param name="srcPath">the SrcPath property of some Image</param>
        /// <returns>ViewPhoto page view</returns>
        public ActionResult ViewPhoto(string srcPath)
        {
            Models.Image im = photosModel.Photos.Find(photo => photo.SrcPath == srcPath);
            ViewBag.PathToFullPic = "Non";
            if (im != null)
            {
                ViewBag.PathToFullPic = photosModel.GetFullImagePath(im);
            }

            return(View(im));
        }
Example #25
0
        /// <summary>
        /// copy the full photo from OutputDir to Images and return the relative path
        /// </summary>
        /// <param name="photo">some photo that in the Images directory</param>
        /// <returns>the relative path to the full photo</returns>
        public string GetFullImagePath(Models.Image photo)
        {
            string fullImagePath = po.SrcFullImPath(photo);
            string projImagePath = po.AbsProjFullImPath(photo);

            if (File.Exists(fullImagePath) && !File.Exists(projImagePath))
            {
                File.Copy(fullImagePath, projImagePath);
            }
            return(po.RelProjFullImPath(photo));
        }
Example #26
0
        public FileStreamResult View(int id)
        {
            Models.Image image = _context.Images.FirstOrDefault(i => i.Id == id);
            if (image == null)
            {
                return(null);
            }

            MemoryStream ms = new MemoryStream(image.Data);

            return(new FileStreamResult(ms, image.ContentType));
        }
 public Lab5_thresholding(Models.Image img, ImageWindow parentWindow)
 {
     InitializeComponent();
     string[] thMethods = new string[] { "Interactive", "Adaptive", "Otsu", "Watershed" };
     ThMethodComboBox.ItemsSource   = thMethods;
     ThMethodComboBox.SelectedIndex = 0;
     ThresholdTB.Text  = threshold.ToString();
     this.parentWindow = parentWindow;
     this.img          = img;
     prev_image        = new Models.Image();
     CloneOrginalImage();
 }
 public HistogramWindow(Models.Image image, ImageWindow parentWindow)
 {
     InitializeComponent();
     this.image       = image;
     Title            = histogramName = string.Format("{0}_Histogram_{1}.bmp", image.filename.Split('.')[0], image.ColorFormat);
     ResizeMode       = ResizeMode.CanMinimize;
     LUT              = image.FindLookUpTable();
     histogramPlotMap = MakeMap();
     LoadKeysToCB();
     colorPicker.SelectedIndex = 0;
     this.parentWindow         = parentWindow;
 }
Example #29
0
        public void UpdateImagePrivacy(int imageId, int privacyLevel)
        {
            Models.Image image = imageRepo.ById(imageId);

            if (image.ProfileId != currentProfile.id)
            {
                return;
            }

            image.PrivacyLevel = privacyLevel;
            imageRepo.SaveImage(image);
        }
Example #30
0
        public bool ListImages(string university, int take, ref string errorMessage, ref List <COP.API.Models.Image> results)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    var imgs = (from d in context.Image
                                where d.University == university
                                orderby d.Id descending
                                select new
                                { id = d.Id, imgUrl = d.Imgurl, uni = d.University }
                                ).Take(take).ToList();

                    if (imgs == null)
                    {
                        errorMessage = "No things";
                        retVal       = false;
                    }
                    else
                    {
                        foreach (var th in imgs)
                        {
                            COP.API.Models.Image z = new Models.Image();

                            z.Id     = (int)th.id;
                            z.ImgUrl = th.imgUrl;
                            if (th.uni == "LBU")
                            {
                                z.University = Models.Image.UniversityEnum.LBU;
                            }
                            else if (th.uni == "LUU")
                            {
                                z.University = Models.Image.UniversityEnum.LUU;
                            }
                            results.Add(z);
                        }
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
        /// <summary>
        /// takes in an image marks that image and saves it the DB
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="fileBytes"></param>
        /// <param name="imageName"></param>
        /// <param name="radio"></param>
        /// <param name="transparentSignatureBackground"></param>
        /// <returns>id of uploaded image</returns>
        public FileUploadResponse FileUpload(int userId, byte[] fileBytes, string imageName, int radio, bool transparentSignatureBackground)
        {
            FileUploadResponse response = new FileUploadResponse();
            var currentUser = _dbContext.Users.Where(x => x.Id == userId).FirstOrDefault();
            currentUser.NumberOfImagesMarked++;


            //create, initialize new markedImage then save to db
            Models.Image markedImage = new Models.Image();
            markedImage.OriginalImageBinary = fileBytes;
            markedImage.Filename = imageName;
            markedImage.UserId = HttpContext.Current.User.Identity.GetUserId<int>();
            markedImage.User = currentUser;
            markedImage.UniqueMark = currentUser.Id + "#" + currentUser.NumberOfImagesMarked;


            string signature = "\\" + TesseractDetection.convertIntToBinarySignature(currentUser.Id) + "#" + TesseractDetection.convertIntToBinarySignature(currentUser.NumberOfImagesMarked) + "#";
            byte[] markedImageBinary = OpenStego.WatermarkImage(radio, signature, fileBytes, transparentSignatureBackground);
            byte[] embeddedAndMarkedImageBinary = OpenStego.EmbedData(markedImage.UniqueMark, markedImageBinary, imageName);

            markedImage.MarkedImageBinary = embeddedAndMarkedImageBinary;
            response.Status = ResultStatus.Success;

            try
            {
                _dbContext.Image.Add(markedImage);
                _dbContext.SaveChanges();
            }
            catch (Exception e)
            {
                Console.Write(e);
                response.Status = ResultStatus.Error;
                response.Message = e.ToString();
            }
            
            response.SignedImageId = markedImage.Id;

            return response;
        }
Example #32
0
        public static async void UploadImageAndAddToDb(int hbID, DateTime TimeTaken, string localFileDirectory, string fileName)
        {
            Task<string> publicURL = UploadImageAndGetPublicUrl(localFileDirectory, fileName);

            using (var db = new DatabaseContext())
            {
                var location = db.Locations.Where(l => l.HitchBotId == hbID)
                    .OrderByDescending(l => l.TakenTime).FirstOrDefault();

                int? locationId = null;

                if (location != null)
                    locationId = location.Id;

                var image = new Models.Image()
                {
                    HitchBotId = hbID,
                    LocationId = locationId,
                    Url = await publicURL,
                    TimeAdded = DateTime.UtcNow,
                    TimeTaken = TimeTaken
                };

                db.Images.Add(image);
                db.SaveChanges();
            }
        }
Example #33
0
        public static async void UploadImageAndAddToDb(int hbID, DateTime TimeTaken, string localFileDirectory, string fileName)
        {
            Task<string> publicURL = UploadImageAndGetPublicUrl(localFileDirectory, fileName);

            using (var db = new Models.Database())
            {
                var hb = db.hitchBOTs.Include(l => l.Locations).FirstOrDefault(l => l.ID == hbID);
                var location = hb.Locations.OrderByDescending(l => l.TakenTime).FirstOrDefault();

                var image = new Models.Image()
                {
                    HitchBOT = hb,
                    Location = location,
                    url = await publicURL,
                    TimeAdded = DateTime.UtcNow,
                    TimeTaken = TimeTaken
                };

                db.Images.Add(image);
                db.SaveChanges();
            }
        }