public async Task <ActionResult <Tamanos> > PostTamanos(Tamanos tamanos)
        {
            _context.Tamanos.Add(tamanos);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTamanos", new { id = tamanos.IdTamano }, tamanos));
        }
        public async Task <IActionResult> PutTamanos(int id, Tamanos tamanos)
        {
            if (id != tamanos.IdTamano)
            {
                return(BadRequest());
            }

            _context.Entry(tamanos).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TamanosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Tamanos> > GetTamanos(int id)
        {
            Tamanos tamanos = await _context.Tamanos.FindAsync(id);

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

            return(tamanos);
        }
        public async Task <ActionResult <Tamanos> > DeleteTamanos(int id)
        {
            Tamanos tamanos = await _context.Tamanos.FindAsync(id);

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

            _context.Tamanos.Remove(tamanos);
            await _context.SaveChangesAsync();

            return(tamanos);
        }
        public String ResizeAndSave(String filename, Stream imageBuffer,Tamanos tamano, bool makeItSquare)
        {

            int newWidth;
            int newHeight;
            Image image = Image.FromStream(imageBuffer);
            int oldWidth = image.Width;
            int oldHeight=image.Height;

            Bitmap newImage;
            String savePath;
            int maxSideSize;
            String urlImage = String.Empty;

            String serverPath = HttpContext.Current.Server.MapPath("~");
            String imagesPath = serverPath + "Content\\Imagenes\\";

            if (tamano == Tamanos.Miniatura)
            {

                urlImage += "~/Content/imagenes/Miniatura/" + filename + ".jpg";
                maxSideSize = 80;
                savePath = imagesPath + "Miniatura\\" + filename + ".jpg";

            }
            else
            {
                urlImage += "~/Content/imagenes/Mediana/" + filename + ".jpg";
                maxSideSize = 600;
                savePath = imagesPath + "Mediana\\" + filename + ".jpg";
            
            }


            if (makeItSquare)
            {
                int smallerSide = oldWidth >= oldHeight ? oldHeight : oldWidth;
                double coeficient = maxSideSize / (double)smallerSide;
                newWidth = Convert.ToInt32(coeficient * oldWidth);
                newHeight = Convert.ToInt32(coeficient * oldHeight);
                Bitmap tempImage = new Bitmap(image, newWidth, newHeight);
                int cropX = (newWidth - maxSideSize) / 2;
                int cropY = (newHeight - maxSideSize) / 2;
                newImage = new Bitmap(maxSideSize, maxSideSize);
                Graphics tempGraphic = Graphics.FromImage(newImage);
                tempGraphic.SmoothingMode = SmoothingMode.AntiAlias;
                tempGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                tempGraphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
                tempGraphic.DrawImage(tempImage, new Rectangle(0, 0, maxSideSize, maxSideSize), cropX, cropY, maxSideSize, maxSideSize, GraphicsUnit.Pixel);


            }
            else
            {
                int maxSide = oldWidth >= oldHeight ? oldWidth : oldHeight;

                if (maxSide > maxSideSize)
                {
                    double coeficient = maxSideSize / (double)maxSide;
                    newWidth = Convert.ToInt32(coeficient * oldWidth);
                    newHeight = Convert.ToInt32(coeficient * oldHeight);
                }
                else
                {
                    newWidth = oldWidth;
                    newHeight = oldHeight;
                }
                try
                {
                    newImage = new Bitmap(image, newWidth, newHeight);
                 
                        newImage.Save(savePath, ImageFormat.Jpeg);
               
                    
                    image.Dispose();
                    newImage.Dispose();
                }
                catch (Exception ex)
                {
                    //explodes at 65567 with "A generic error occurred in GDI+."

                
                }
            
            }
            return urlImage;
        }
Example #6
0
        public string ResizeAndSave(string FileName, Stream imageBuffer, Tamanos tamano, bool makeItSquare)
        {
            int    newWidth;
            int    newHeight;
            Image  image     = Image.FromStream(imageBuffer);
            int    oldWidth  = image.Width;
            int    oldHeight = image.Height;
            Bitmap newImage;
            string savePath;
            int    maxSideSize;
            string urlImagen = string.Empty;

            string serverPath = HttpContext.Current.Server.MapPath("~");
            string imagesPath = serverPath + "Content\\Imagenes\\";

            if (tamano == Tamanos.Miniatura)
            {
                urlImagen  += "~/content/imagenes/Miniatura/" + FileName + ".jpg";
                maxSideSize = 80;
                savePath    = imagesPath + "Miniatura\\" + FileName + ".jpg";
            }

            else
            {
                urlImagen  += "~/content/imagenes/Mediana/" + FileName + ".jpg";
                maxSideSize = 80;
                savePath    = imagesPath + "Mediana\\" + FileName + ".jpg";
            }


            if (makeItSquare)
            {
                int    smallerSide = oldWidth >= oldHeight ? oldHeight : oldWidth;
                double coeficient  = maxSideSize / (double)smallerSide;
                newWidth  = Convert.ToInt32(coeficient * oldWidth);
                newHeight = Convert.ToInt32(coeficient * oldHeight);
                Bitmap tempImage = new Bitmap(image, newWidth, newHeight);
                int    cropx     = (newWidth - maxSideSize) / 2;
                int    cropy     = (newHeight - maxSideSize) / 2;
                newImage = new Bitmap(maxSideSize, maxSideSize);
                Graphics tempGraphics = Graphics.FromImage(newImage);
                tempGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
                tempGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                tempGraphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                tempGraphics.DrawImage(tempImage, new Rectangle(0, 0, maxSideSize, maxSideSize));
            }

            else
            {
                int maxside = oldWidth >= oldHeight ? oldWidth : oldHeight;

                if (maxside > maxSideSize)
                {
                    double coeficient = maxSideSize / (double)maxside;
                    newWidth  = Convert.ToInt32(coeficient * oldWidth);
                    newHeight = Convert.ToInt32(coeficient * oldHeight);
                }

                else
                {
                    newWidth  = oldWidth;
                    newHeight = oldHeight;
                }
                newImage = new Bitmap(image, newWidth, newHeight);
            }

            newImage.Save(savePath, ImageFormat.Jpeg);
            image.Dispose();

            return(urlImagen);
        }
        public String ResizeAndSave(String filename, Stream imageBuffer, Tamanos tamano, bool makeItSquare)
        {
            int   newWidth;
            int   newHeight;
            Image image     = Image.FromStream(imageBuffer);
            int   oldWidth  = image.Width;
            int   oldHeight = image.Height;

            Bitmap newImage;
            String savePath;
            int    maxSideSize;
            String urlImage = String.Empty;

            String serverPath = HttpContext.Current.Server.MapPath("~");
            String imagesPath = serverPath + "Content\\Imagenes\\";

            if (tamano == Tamanos.Miniatura)
            {
                urlImage   += "~/Content/imagenes/Miniatura/" + filename + ".jpg";
                maxSideSize = 80;
                savePath    = imagesPath + "Miniatura\\" + filename + ".jpg";
            }
            else
            {
                urlImage   += "~/Content/imagenes/Mediana/" + filename + ".jpg";
                maxSideSize = 600;
                savePath    = imagesPath + "Mediana\\" + filename + ".jpg";
            }


            if (makeItSquare)
            {
                int    smallerSide = oldWidth >= oldHeight ? oldHeight : oldWidth;
                double coeficient  = maxSideSize / (double)smallerSide;
                newWidth  = Convert.ToInt32(coeficient * oldWidth);
                newHeight = Convert.ToInt32(coeficient * oldHeight);
                Bitmap tempImage = new Bitmap(image, newWidth, newHeight);
                int    cropX     = (newWidth - maxSideSize) / 2;
                int    cropY     = (newHeight - maxSideSize) / 2;
                newImage = new Bitmap(maxSideSize, maxSideSize);
                Graphics tempGraphic = Graphics.FromImage(newImage);
                tempGraphic.SmoothingMode     = SmoothingMode.AntiAlias;
                tempGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                tempGraphic.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                tempGraphic.DrawImage(tempImage, new Rectangle(0, 0, maxSideSize, maxSideSize), cropX, cropY, maxSideSize, maxSideSize, GraphicsUnit.Pixel);
            }
            else
            {
                int maxSide = oldWidth >= oldHeight ? oldWidth : oldHeight;

                if (maxSide > maxSideSize)
                {
                    double coeficient = maxSideSize / (double)maxSide;
                    newWidth  = Convert.ToInt32(coeficient * oldWidth);
                    newHeight = Convert.ToInt32(coeficient * oldHeight);
                }
                else
                {
                    newWidth  = oldWidth;
                    newHeight = oldHeight;
                }
                try
                {
                    newImage = new Bitmap(image, newWidth, newHeight);

                    newImage.Save(savePath, ImageFormat.Jpeg);


                    image.Dispose();
                    newImage.Dispose();
                }
                catch (Exception ex)
                {
                    //explodes at 65567 with "A generic error occurred in GDI+."
                }
            }
            return(urlImage);
        }
Example #8
0
 internal string ResizeAndSave(string filename, object inputStream, Tamanos miniatura, bool v)
 {
     throw new NotImplementedException();
 }