Esempio n. 1
0
        public static void ResizeImage(string originalFile, string newFile, int newWidth, int maxHeight, bool onlyResizeIfWider)
        {
            System.Drawing.Image fullsizeImage = System.Drawing.Image.FromFile(originalFile);

            fullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            fullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (onlyResizeIfWider)
            {
                if (fullsizeImage.Width <= newWidth)
                {
                    newWidth = fullsizeImage.Width;
                }
            }

            int newHeight = fullsizeImage.Height * newWidth / fullsizeImage.Width;

            if (newHeight > maxHeight)
            {
                newWidth  = fullsizeImage.Width * maxHeight / fullsizeImage.Height;
                newHeight = maxHeight;
            }

            System.Drawing.Image newImage = fullsizeImage.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);

            fullsizeImage.Dispose();

            newImage.Save(newFile);
        }
Esempio n. 2
0
        public static bool ScaleImage(string sourcePath, string destPath, int maxWidth, int maxHeight, double maxMB, int quality, int rotationDeg)
        {
            bool result = false;

            try
            {
                //todo: check result if size in MB is not above max.
                //for now, just apply the max size in pixels
                System.Drawing.Image image = System.Drawing.Image.FromFile(sourcePath);
                if (rotationDeg == 180)
                {
                    image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                }
                else if (rotationDeg == 90)
                {
                    image.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                }
                else if (rotationDeg == 270)
                {
                    image.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                }
                //max size
                System.Drawing.Size   sz1 = ImageUtilities.GetNewSize(new System.Drawing.Size(image.Size.Width, image.Size.Height), new System.Drawing.Size(maxWidth, maxHeight));
                System.Drawing.Bitmap bmp = ImageUtilities.ResizeImage(image, sz1.Width, sz1.Height);
                ImageUtilities.SaveJpeg(destPath, bmp, quality);

                result = true;
            }
            catch
            {
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Rotate bitmap file pathSrc and save to pathDst.
        /// </summary>
        /// <param name="angle" > value: "0", "90", "180", "270" </param>
        private static void SaveRotatedImage(string pathSrc, string pathDst, string angle)
        {
            int nAngle = 0;

            if (int.TryParse(angle, out nAngle) && nAngle % 90 == 0)
            {
                System.Drawing.Image i = System.Drawing.Image.FromFile(pathSrc);

                switch (nAngle % 360)
                {
                case 90:
                    i.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                    break;

                case 180:
                    // Fixed #0059623: It seem there is bugs in Rotate180FlipNone.
                    i.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                    i.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                    break;

                case 270:
                    i.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                    break;

                default:
                    i.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                    break;
                }

                i.Save(pathDst, System.Drawing.Imaging.ImageFormat.Bmp);
            }
        }
Esempio n. 4
0
        public void ResizeImage(string OrigFile, string NewFile, int NewWidth, int MaxHeight, bool ResizeIfWider)
        {
            System.Drawing.Image FullSizeImage = System.Drawing.Image.FromFile(OrigFile);

            // Ensure the generated thumbnail is not being used by rotating it 360 degrees
            FullSizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullSizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (ResizeIfWider)
            {
                if (FullSizeImage.Width <= NewWidth)
                {
                    NewWidth = FullSizeImage.Width;
                }
            }

            int NewHeight = FullSizeImage.Height * NewWidth / FullSizeImage.Width;

            if (NewHeight > MaxHeight)   // Height resize if necessary
            {
                NewWidth  = FullSizeImage.Width * MaxHeight / FullSizeImage.Height;
                NewHeight = MaxHeight;
            }

            // Create the new image with the sizes we've calculated
            System.Drawing.Image NewImage = FullSizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
            FullSizeImage.Dispose();
            NewImage.Save(NewFile);
        }
Esempio n. 5
0
        public static void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
        {
            System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);

            // Prevent using images internal thumbnail
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (OnlyResizeIfWider)
            {
                if (FullsizeImage.Width <= NewWidth)
                {
                    NewWidth = FullsizeImage.Width;
                }
            }

            int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;

            if (NewHeight > MaxHeight)
            {
                // Resize with height instead
                NewWidth  = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
                NewHeight = MaxHeight;
            }

            System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

            // Clear handle to original file so that we can overwrite it if necessary
            FullsizeImage.Dispose();

            // Save resized picture
            NewImage.Save(NewFile);
        }
Esempio n. 6
0
        public static void ResizeImage(Stream originalStream, Stream outStream, int newWidth,
                                       int maxHeight, bool onlyResizeIfWider, ImageFormat saveFormat)
        {
            System.Drawing.Image FullsizeImage = System.Drawing.Image.FromStream(originalStream);

            // Prevent using images internal thumbnail
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (onlyResizeIfWider)
            {
                if (FullsizeImage.Width <= newWidth)
                {
                    newWidth = FullsizeImage.Width;
                }
            }

            int NewHeight = FullsizeImage.Height * newWidth / FullsizeImage.Width;

            if (NewHeight > maxHeight)
            {
                // Resize with height instead
                newWidth  = FullsizeImage.Width * maxHeight / FullsizeImage.Height;
                NewHeight = maxHeight;
            }

            System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(newWidth, NewHeight, null, IntPtr.Zero);

            // Clear handle to original file so that we can overwrite it if necessary
            FullsizeImage.Dispose();

            // Save resized picture
            NewImage.Save(outStream, saveFormat);
        }
Esempio n. 7
0
        public static System.Drawing.Image OrientImage(System.Drawing.Image image)
        {
            int orientationId = 0x0112;

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

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

                case 3:     // bottoms up
                    image.RotateFlip(rotateFlipType: System.Drawing.RotateFlipType.Rotate180FlipNone);
                    break;

                case 6:     // rotated 90 left
                    image.RotateFlip(rotateFlipType: System.Drawing.RotateFlipType.Rotate90FlipNone);
                    break;
                }
                image.RemovePropertyItem(orientationId);
            }

            return(image);
        }
Esempio n. 8
0
        public static System.Drawing.Image ResizeImage(this System.Drawing.Image FullsizeImage, int NewWidth, int MaxHeight, bool OnlyResizeIfWider = true)
        {
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (OnlyResizeIfWider)
            {
                if (FullsizeImage.Width <= NewWidth)
                {
                    NewWidth = FullsizeImage.Width;
                }
            }

            int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;

            if (NewHeight > MaxHeight)
            {
                NewWidth  = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
                NewHeight = MaxHeight;
            }

            System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

            FullsizeImage.Dispose();

            return(NewImage);
        }
Esempio n. 9
0
        public static void Resize(string originalFile, string newFile, int newWidth, int maxHeight, bool onlyResizeIfWider)
        {
            System.Drawing.Image fullsizeImage = System.Drawing.Image.FromFile(originalFile);

            // Prevent using images internal thumbnail
            fullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            fullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (onlyResizeIfWider && fullsizeImage.Width <= newWidth)
            {
                newWidth = fullsizeImage.Width;
            }

            int newHeight = fullsizeImage.Height * newWidth / fullsizeImage.Width;

            if (newHeight > maxHeight)
            {
                // Resize with height instead
                newWidth  = fullsizeImage.Width * maxHeight / fullsizeImage.Height;
                newHeight = maxHeight;
            }

            System.Drawing.Image newImage = fullsizeImage.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);

            // Clear handle to original file so that we can overwrite it if necessary
            fullsizeImage.Dispose();

            // Save resized picture
            newImage.Save(newFile);
        }
        public ActionResult Add(Image imageModel)

        {
            // System.Drawing.Image img = System.Drawing.Image.FromFile("C:/Users/18651/source/repos/WebApplication1/WebApplication1/Image/IMG_8148183549382.JPG");
            System.Drawing.Image originalImage = System.Drawing.Image.FromStream(imageModel.ImageFile.InputStream);
            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: System.Drawing.RotateFlipType.Rotate270FlipNone);
                    break;

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



                    break;

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


            string fileName  = Path.GetFileNameWithoutExtension(imageModel.ImageFile.FileName);
            string extension = Path.GetExtension(imageModel.ImageFile.FileName);

            fileName             = fileName + DateTime.Now.ToString("yymmssfff") + extension;
            imageModel.ImagePath = "~/Image/" + fileName;
            fileName             = Path.Combine(Server.MapPath("~/Image/"), fileName);

            imageModel.ImageFile.SaveAs(fileName);
            using (DbModels db = new DbModels())
            {
                db.Images.Add(imageModel);
                db.SaveChanges();
            }
            originalImage.Save(fileName);
            ModelState.Clear();


            return(View());
        }
Esempio n. 11
0
        public void virar(int i)
        {
            System.Drawing.Image temp = car.Image;

            if (sentido == AnchorStyles.Right)
            {
                if (i == 1)
                {
                    sentido = AnchorStyles.Top;
                    temp.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                }
                else
                {
                    temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                    sentido = AnchorStyles.Bottom;
                }
            }
            else if (sentido == AnchorStyles.Left)
            {
                if (i == 1)
                {
                    sentido = AnchorStyles.Bottom;
                    temp.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                }
                else
                {
                    temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                    sentido = AnchorStyles.Top;
                }
            }
            else if (sentido == AnchorStyles.Top)
            {
                if (i == 1)
                {
                    sentido = AnchorStyles.Left;
                    temp.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                }
                else
                {
                    temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                    sentido = AnchorStyles.Right;
                }
            }
            else
            {
                if (i == 1)
                {
                    sentido = AnchorStyles.Right;
                    temp.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                }
                else
                {
                    temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                    sentido = AnchorStyles.Left;
                }
            }

            car.Image = temp;
        }
Esempio n. 12
0
        void RotatePicture(System.Drawing.RotateFlipType rotateType)
        {
            string sPicturePath = ViewState["sPicturePath"] as string;

            if (null == sPicturePath)
            {
                return;
            }

            System.Drawing.Image image = null;
            string imageFileName       = Server.MapPath(sPicturePath);

            try
            {
                image = System.Drawing.Image.FromFile(imageFileName);

                image.RotateFlip(rotateType);
                image.Save(imageFileName);
                //Response.Redirect(Request.QueryString["r"]);
                Image1.ImageUrl = "ShrinkImage.aspx?i=" + sPicturePath + "&w=900";
            }
            finally
            {
                if (null != image)
                {
                    image.Dispose();
                }
            }
        }
Esempio n. 13
0
        public static System.Drawing.Image GetResizedImage(System.Drawing.Image FullsizeImage, int newWidth, int maxHeight)
        {
            //System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(orginalImageFileName);
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            int NewHeight = FullsizeImage.Height * newWidth / FullsizeImage.Width;

            if (NewHeight > maxHeight)
            {
                newWidth  = FullsizeImage.Width * maxHeight / FullsizeImage.Height;
                NewHeight = maxHeight;
            }
            System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(newWidth, NewHeight, null, IntPtr.Zero);
            FullsizeImage.Dispose();
            return(NewImage);
        }
Esempio n. 14
0
        public static void ResizeImage(string OriginalFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
        {
            if (OriginalFile.StartsWith("."))
            {
                return;
            }

            try
            {
                FileInfo OrigFileInfo = new FileInfo(OriginalFile);

                System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);

                // Prevent using images internal thumbnail
                FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

                if (OnlyResizeIfWider)
                {
                    if (FullsizeImage.Width <= NewWidth)
                    {
                        NewWidth = FullsizeImage.Width;
                    }
                }

                int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
                if (NewHeight > MaxHeight)
                {
                    // Resize with height instead
                    NewWidth  = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
                    NewHeight = MaxHeight;
                }

                System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

                // Clear handle to original file so that we can overwrite it if necessary
                FullsizeImage.Dispose();

                // Save resized picture
                NewImage.Save(OrigFileInfo.DirectoryName + "/resized/" + OrigFileInfo.Name);
            }
            catch (Exception ex)
            {
                ErrorHelper.LogException(ex);
            }
        }
Esempio n. 15
0
        private void generujAktualnyObrazek()
        {
            _obrazekRoboczy.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, this._aktualnaStrona);
            this._szerokosc = _obrazekRoboczy.Width;
            this._wysokosc  = _obrazekRoboczy.Height;
            System.Drawing.Image tmp = _obrazekRoboczy.GetThumbnailImage(this._szerokosc * this._skala / 100, this._wysokosc * this._skala / 100, null, IntPtr.Zero);
            switch (_orientacja)
            {
            case OrientacjaObrazka.ObrotPrawo90: tmp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); break;

            case OrientacjaObrazka.ObrotLewo90: tmp.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone); break;

            case OrientacjaObrazka.Obrot180: tmp.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone); break;
            }
            tmp.Save(HttpContext.Current.Server.MapPath(UrlObrazka), System.Drawing.Imaging.ImageFormat.Gif); // wywalic do konfiguracji
            tmp.Dispose();
        }
Esempio n. 16
0
        private string ResizeImage(string storageDir, string originalFile, int newWidth, int maxHeight, bool onlyResizeIfWider)
        {
            System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(storageDir + originalFile);

            // Prevent using images internal thumbnail
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (onlyResizeIfWider)
            {
                if (FullsizeImage.Width <= newWidth)
                {
                    newWidth = FullsizeImage.Width;

                    return(originalFile);
                }
            }

            int NewHeight = FullsizeImage.Height * newWidth / FullsizeImage.Width;

            if (NewHeight > maxHeight)
            {
                // Resize with height instead
                newWidth  = FullsizeImage.Width * maxHeight / FullsizeImage.Height;
                NewHeight = maxHeight;
            }

            System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(newWidth, NewHeight, null, IntPtr.Zero);

            // Clear handle to original file so that we can overwrite it if necessary
            FullsizeImage.Dispose();

            DirectoryInfo resizedir = new DirectoryInfo(storageDir + "/rs");

            if (!resizedir.Exists)
            {
                resizedir.Create();
            }

            // Save resized picture
            NewImage.Save(storageDir + "/rs/" + originalFile);

            return("rs/" + originalFile);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    string id = Request.QueryString[0].ToString();
                    if (!string.IsNullOrWhiteSpace(id))
                    {
                        List <string> scrnoa = new List <string>();
                        scrnoa = clsProcesCardlst.ProcesCardlst;

                        List <clsimgprop> datalist = new List <clsimgprop>();

                        clsimgprop data;

                        string clss = "hori";
                        if (id == "0")
                        {
                            clss = "hori";
                        }
                        else
                        {
                            for (int i = 0; i < scrnoa.Count; i++)
                            {
                                data     = new clsimgprop();
                                data.Img = MapPath("~/StdICard/" + HttpContext.Current.Session["SchoolId"].ToString() + "/School_" + scrnoa[i] + ".jpg");

                                System.Drawing.Image image = System.Drawing.Image.FromFile(data.Img);
                                image.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                                image.Save(data.Img);
                            }
                        }



                        if (scrnoa != null)
                        {
                            for (int i = 0; i < scrnoa.Count; i++)
                            {
                                data     = new clsimgprop();
                                data.Img = "StdICard/" + HttpContext.Current.Session["SchoolId"].ToString() + "/School_" + scrnoa[i] + ".jpg";
                                data.cls = clss;
                                datalist.Add(data);
                            }
                            rpt1.DataSource = datalist;
                            rpt1.DataBind();
                        }
                    }
                }
                catch
                {
                    Response.Redirect("PrintDataSelect.aspx");
                }
            }
        }
Esempio n. 18
0
        public ActionResult ImgRotateD(string file)
        {
            string path = Server.MapPath("~/Content/Immagini/Servizi/" + file);

            System.Drawing.Image img = System.Drawing.Image.FromFile(path);
            img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipXY);
            img.Save(path);
            img.Dispose();
            return(RedirectToAction("Galleria", "Servizis"));
        }
Esempio n. 19
0
        public void ResizeImage(Stream original, string newFile, int newWidth, int maxHeight, bool onlyResizeIfWider)
        {
            System.Drawing.Image FullsizeImage = System.Drawing.Image.FromStream(original);

            // Prevent using images internal thumbnail
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (onlyResizeIfWider)
            {
                if (FullsizeImage.Width <= newWidth)
                {
                    newWidth = FullsizeImage.Width;
                }
            }

            int NewHeight = FullsizeImage.Height * newWidth / FullsizeImage.Width;

            if (NewHeight > maxHeight)
            {
                // Resize with height instead
                newWidth  = FullsizeImage.Width * maxHeight / FullsizeImage.Height;
                NewHeight = maxHeight;
            }

            var NewImage = FullsizeImage.GetThumbnailImage(newWidth, NewHeight, null, IntPtr.Zero);

            // Clear handle to original file so that we can overwrite it if necessary
            FullsizeImage.Dispose();

            // Save resized picture
            using (Stream s = new MemoryStream())
            {
                NewImage.Save(s, System.Drawing.Imaging.ImageFormat.Png);
                s.Flush();
                s.Position = 0;
                var kernel = new StandardKernel(new NinjectModule());
                kernel.Get <IImageStore>().Save(newFile, s, "string/png");
            }
        }
Esempio n. 20
0
        public void definir_sentido(AnchorStyles sentido)
        {
            this.sentido = sentido;

            System.Drawing.Image temp = car.Image;

            if (sentido == AnchorStyles.Right)
            {
                temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
            }
            else if (sentido == AnchorStyles.Left)
            {
            }
            else if (sentido == AnchorStyles.Top)
            {
                temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
            }
            else
            {
                temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                temp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
            }

            car.Image = temp;
        }
        /// <summary>
        /// Resizes image
        /// </summary>
        /// <param name="imageBytes"></param>
        /// <param name="NewWidth"></param>
        /// <param name="MaxHeight"></param>
        /// <param name="OnlyResizeIfWider"></param>
        /// <param name="imageFormat"></param>
        /// <returns></returns>
        public byte[] ResizeImage(byte[] imageBytes, int NewWidth, int MaxHeight, bool OnlyResizeIfWider, IImageFormatSpec imageFormatSpec)
        {
            using (var ms = new MemoryStream(imageBytes))
            {
                System.Drawing.Image FullsizeImage = System.Drawing.Image.FromStream(ms);

                // Prevent using images internal thumbnail
                FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

                if (OnlyResizeIfWider)
                {
                    if (FullsizeImage.Width <= NewWidth)
                    {
                        NewWidth = FullsizeImage.Width;
                    }
                }

                int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
                if (NewHeight > MaxHeight)
                {
                    // Resize with height instead
                    NewWidth  = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
                    NewHeight = MaxHeight;
                }

                System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

                // Clear handle to original file so that we can overwrite it if necessary
                FullsizeImage.Dispose();

                // Save resized picture
                using (var msOut = new MemoryStream())
                {
                    NewImage.Save(msOut, imageFormatSpec.Format);
                    return(msOut.GetBuffer());
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="sourceModification"></param>
        /// <param name="destination"></param>
        public void BakeTexture(Texture2D texture, System.Drawing.RotateFlipType sourceModification, Rectangle destination)
        {
            Stream sourceBuffer = new MemoryStream();

            texture.SaveAsPng(sourceBuffer, texture.Width, texture.Height);

            System.Drawing.Image sourceImage = System.Drawing.Image.FromStream(sourceBuffer);

            sourceBuffer = new MemoryStream();
            sourceImage.RotateFlip(sourceModification);
            sourceImage.Save(sourceBuffer, System.Drawing.Imaging.ImageFormat.Png);

            _batch.Draw(
                Texture2D.FromStream(_graphicsDevice, sourceBuffer),
                destination,
                Color.White);
        }
Esempio n. 23
0
        public System.Drawing.RotateFlipType ExifRotate(System.Drawing.Image img)
        {
            // for some reason iText does not respect orientation stored in metadata as it seams...
            // try to fix it with this weird stuff...
            // based on https://www.cyotek.com/blog/handling-the-orientation-exif-tag-in-images-using-csharp

            const int exifOrientationID = 0x112; //274

            if (!img.PropertyIdList.Contains(exifOrientationID))
            {
                return(System.Drawing.RotateFlipType.RotateNoneFlipNone);
            }

            var prop = img.GetPropertyItem(exifOrientationID);
            int val  = BitConverter.ToUInt16(prop.Value, 0);
            var rot  = System.Drawing.RotateFlipType.RotateNoneFlipNone;

            if (val == 3 || val == 4)
            {
                rot = System.Drawing.RotateFlipType.Rotate180FlipNone;
            }
            else if (val == 5 || val == 6)
            {
                rot = System.Drawing.RotateFlipType.Rotate90FlipNone;
            }
            else if (val == 7 || val == 8)
            {
                rot = System.Drawing.RotateFlipType.Rotate270FlipNone;
            }

            if (val == 2 || val == 4 || val == 5 || val == 7)
            {
                rot |= System.Drawing.RotateFlipType.RotateNoneFlipX;
            }

            if (rot != System.Drawing.RotateFlipType.RotateNoneFlipNone)
            {
                img.RotateFlip(rot);
            }

            return(rot);
        }
Esempio n. 24
0
        public TradelaneFile ShipmentBagLabel(int BagId, int userId)
        {
            TradelaneFile result = new TradelaneFile();

            List <ExpressReportBagLabel> model = new ExpressReportRepository().GetBagLabelReportObj(BagId, userId);

            // List<TradelaneBookingReportMAWB> model = new TradelaneReportsRepository().GetMAWBObj(tradelaneShipmentId);
            ReportTemplate.Express.EXSBagLabel report = new ReportTemplate.Express.EXSBagLabel();
            report.DataSource = model;
            ImageExportOptions options = new ImageExportOptions();

            options.Resolution = 150;
            string fileName = "EXS-BGL-" + model[0].Hub + "-" + model[0].Ref + ".jpeg";
            //int tradelaneShipmentId = model[0].TradelaneShipmentId;

            string filePath         = AppSettings.WebApiPath + "/UploadFiles/ExpressBag/" + BagId + "/" + fileName;
            string filePhysicalPath = HttpContext.Current.Server.MapPath("~/UploadFiles/ExpressBag/" + BagId + "/" + fileName);

            if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("~/UploadFiles/ExpressBag/" + BagId + "/")))
            {
                System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/UploadFiles/ExpressBag/" + BagId + "/"));
            }

            if (File.Exists(filePhysicalPath))
            {
                File.Delete(filePhysicalPath);
            }
            report.ExportToImage(filePhysicalPath, options);

            string resultPath = @"" + filePhysicalPath + "";

            using (System.Drawing.Image img = System.Drawing.Image.FromFile(resultPath))
            {
                img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                resultPath = @"" + filePhysicalPath + "";
                img.Save(resultPath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }

            result.FileName = fileName;
            result.FilePath = filePath;
            return(result);
        }
        public static void DeleteCustomer(string id)
        {
            List <string> scrnoa = new List <string>();

            scrnoa = clsProcesCardlst.ProcesCardlst;
            clsimgprop data;

            if (id != "0")
            {
                for (int i = 0; i < scrnoa.Count; i++)
                {
                    data     = new clsimgprop();
                    data.Img = HostingEnvironment.MapPath("~/StdICard/" + HttpContext.Current.Session["SchoolId"].ToString() + "/School_" + scrnoa[i] + ".jpg");

                    System.Drawing.Image image = System.Drawing.Image.FromFile(data.Img);
                    image.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                    image.Save(data.Img);
                }
            }
        }
Esempio n. 26
0
        public TradelaneFile ShipmentCartonLabel(int tradelaneShipmentId, int CartonCount, int TradelaneShipmentDetailId, string Hawb)
        {
            TradelaneFile result = new TradelaneFile();

            var model = new TradelaneReportsRepository().GetCartonLabelObj(tradelaneShipmentId, Hawb);

            ReportTemplate.Tradelane.PackageLabel shipmentDetailReport = new Report.Generator.ReportTemplate.Tradelane.PackageLabel();
            model.FirstOrDefault().ScannedPieces = int.Parse(model.FirstOrDefault().TotalPieces);
            model.FirstOrDefault().TotalPieces   = model.FirstOrDefault().HawbScannedCarton + "/" + model.FirstOrDefault().HAWBTotalPieces;
            shipmentDetailReport.DataSource = model;
            ImageExportOptions options = new ImageExportOptions();

            options.Resolution = 150;
            var    Name             = new TradelaneBookingRepository().GetLastScannedCarton(tradelaneShipmentId);
            string fileName         = Name + ".jpeg";
            string filePath         = AppSettings.WebApiPath + "/UploadFiles/Tradelane/" + tradelaneShipmentId + "/" + fileName;
            string filePhysicalPath = HttpContext.Current.Server.MapPath("~/UploadFiles/Tradelane/" + tradelaneShipmentId + "/" + fileName);

            if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("~/UploadFiles/Tradelane/" + tradelaneShipmentId + "/")))
            {
                System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/UploadFiles/Tradelane/" + tradelaneShipmentId + "/"));
            }
            if (File.Exists(filePhysicalPath))
            {
                File.Delete(filePhysicalPath);
            }

            shipmentDetailReport.ExportToImage(filePhysicalPath, options);

            string resultPath = @"" + filePhysicalPath + "";

            using (System.Drawing.Image img = System.Drawing.Image.FromFile(resultPath))
            {
                img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                resultPath = @"" + filePhysicalPath + "";
                img.Save(resultPath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            result.FileName = fileName;
            result.FilePath = filePath;
            return(result);
        }
Esempio n. 27
0
        static public void Print(string printPath, string actualPrinter, short actualNumberOfCopies)
        {
            PrintDocument pd = new PrintDocument();

            PrintController printController = new StandardPrintController();

            pd.PrintController = printController;

            pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
            pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
            pd.PrintPage += (sndr, args) =>
            {
                System.Drawing.Image i = System.Drawing.Image.FromFile(printPath);
                i.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                System.Drawing.Rectangle m = args.MarginBounds;

                if ((double)i.Width / (double)i.Height > (double)m.Width / (double)m.Height)
                {
                    m.Height = (int)((double)i.Height / (double)i.Width * (double)m.Width);
                }
                else
                {
                    m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height);
                }

                pd.DefaultPageSettings.Landscape = m.Height > m.Width;
                m.Y = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Height - m.Height) / 2);
                m.X = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Width - m.Width) / 2);
                args.Graphics.DrawImage(i, m);
            };

            pd.PrinterSettings.PrinterName = actualPrinter;
            Debug.WriteLine("actual number of copies: " + actualNumberOfCopies);
//            pd.PrinterSettings.Copies = actualNumberOfCopies;
//            pd.Print();
            for (int i = 0; i < actualNumberOfCopies; i++)
            {
                pd.Print();
            }
        }
Esempio n. 28
0
        private static void UpdateImage()
        {
            if (connected)
            {
                lock (lockUpdate)
                {
                    try
                    {
                        if (useAvicap)
                        {
                            SendMessage(hWnd, WM_CAP_GET_FRAME, 0, 0);
                            SendMessage(hWnd, WM_CAP_COPY, 0, 0);
                            dImg = System.Windows.Forms.Clipboard.GetImage();
                        }
                        else
                        {
                            if (null == bitmap) return;
                            dImg = (System.Drawing.Bitmap)bitmap.Clone();
                            dImg.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
                        }
                        System.Drawing.Image.GetThumbnailImageAbort dummyCallback = new System.Drawing.Image.GetThumbnailImageAbort(ResizeAbort);
                        if (_width < dImg.Width && _height < dImg.Height) dImg = dImg.GetThumbnailImage(_width, _height, dummyCallback, IntPtr.Zero);
                        dImg = DoEffect(dImg, effect, _parameter);

                        FastThread.Invoke(UpdateImage_Delegate);
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                    }
                }
            }
        }
Esempio n. 29
0
        private void LoadImage(string filename)
        {
            FullScreenImage.RenderTransform = null;
            FullScreenImage.Visibility      = Visibility.Visible;
            FullScreenMedia.Visibility      = Visibility.Collapsed;

            Overlay.Text = "";

            if (Path.GetExtension(filename).ToLower() == ".jpg") // load exif only for jpg
            {
                UInt16 orient = 1;
                try
                {
                    var exif = new ExifUtils();
                    if (exif.ReadExifFromFile(filename))
                    {
                        orient       = exif.GetOrientation();
                        Overlay.Text = filename + Environment.NewLine + exif.GetInfoString();
                    }
                    else
                    {
                        Overlay.Text = "";
                    }
                }
                catch
                {
                    ShowError("Can not load exif data");
                    infoShowingTimer.Start();
                }

                // Rotate image per user request (R key)
                if (imageRotationAngle == 90)
                {
                    try
                    {
                        orient = ExifUtils.RotateImageViaInPlaceBitmapMetadataWriter(filename, orient);
                    }
                    catch //InPlaceBitmapMetadataWriter can only work when there is already orientation exif. if image doesn`t have it we will use transcoding
                    {
                        orient = ExifUtils.RotateImageViaTranscoding(filename, orient);
                    }
                }

                // Get rotation angle per EXIF orientation
                var fType = ExifUtils.GetRotateFlipTypeByExifOrientationData(orient);
                imageRotationAngle = ExifUtils.GetBitmapRotationAngleByRotationFlipType(fType);
            }
            else   //if (Path.GetExtension(filename).ToLower() == ".jpg")
            {
                if (imageRotationAngle == 90)
                {
                    try
                    {
                        //rotate other types of image using Image class
                        using (FileStream imgStream = File.Open(filename, FileMode.Open, FileAccess.ReadWrite))
                            using (Image imgForRotation = Image.FromStream(imgStream, false, false))
                            {
                                imgForRotation.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                                imgStream.Seek(0, SeekOrigin.Begin);
                                switch (Path.GetExtension(filename).ToLower())
                                {
                                case ".png":
                                    imgForRotation.Save(imgStream, ImageFormat.Png);
                                    break;

                                case ".bmp":
                                    imgForRotation.Save(imgStream, ImageFormat.Bmp);
                                    break;

                                case ".gif":
                                    imgForRotation.Save(imgStream, ImageFormat.Gif);
                                    break;
                                }
                                imgStream.Flush();
                                imgStream.Close();
                            }
                        imageRotationAngle = 0; // because we already have rotated image
                    }
                    catch (Exception e)
                    {
                        ShowError(e.Message);
                        infoShowingTimer.Start();
                    }
                }
            }

            try
            {
                using (
                    var imgStream = File.Open(filename, FileMode.Open, FileAccess.Read,
                                              FileShare.Delete | FileShare.Read))
                {
                    var img = new BitmapImage();
                    img.BeginInit();
                    img.CacheOption = BitmapCacheOption.OnLoad;

                    img.StreamSource = imgStream; // load image from stream instead of file
                    img.EndInit();

                    // Rotate Image if necessary
                    TransformedBitmap transformBmp = new TransformedBitmap();
                    transformBmp.BeginInit();
                    transformBmp.Source = img;
                    RotateTransform transform = new RotateTransform(imageRotationAngle);
                    transformBmp.Transform = transform;
                    transformBmp.EndInit();
                    FullScreenImage.Source = transformBmp;
                    // Initialize rotation variable for next image
                    imageRotationAngle = 0;

                    imageTimer.Start();

                    //if we failed to get exif data set some basic info
                    if (String.IsNullOrWhiteSpace(Overlay.Text))
                    {
                        Overlay.Text = filename + "\n" + (int)img.Width + "x" + (int)img.Height;
                    }
                }
            }
            catch
            {
                FullScreenImage.Source = null;
                ShowError("Can not load " + filename + " ! Screensaver paused, press P to unpause.");
            }
        }
Esempio n. 30
0
        private void LoadImage(string filename)
        {
            FullScreenImage.RenderTransform = null;
            FullScreenImage.Visibility      = Visibility.Visible;
            FullScreenMedia.Visibility      = Visibility.Collapsed;
            try
            {
                using (
                    var imgStream = File.Open(filename, FileMode.Open, FileAccess.Read,
                                              FileShare.Delete | FileShare.ReadWrite))
                {
                    using (Image imgForExif = Image.FromStream(imgStream, false, false))
                    {
                        // Check to see if image display needs to be rotated per EXIF Orientation parameter (274) or user R key input
                        if (Array.IndexOf(imgForExif.PropertyIdList, 274) > -1)
                        {
                            PropertyItem orientation = imgForExif.GetPropertyItem(274);
                            var          fType       = GetRotateFlipTypeByExifOrientationData((int)orientation.Value[0]);

                            // Check to see if user requested rotation (R key)
                            if (imageRotationAngle == 90)
                            {
                                orientation.Value = BitConverter.GetBytes((int)GetNextRotationOrientation((int)orientation.Value[0]));
                                // Set EXIF tag property to new orientation
                                imgForExif.SetPropertyItem(orientation);
                                // update RotateFlipType accordingly
                                fType = GetRotateFlipTypeByExifOrientationData((int)orientation.Value[0]);

                                //Rotate90(filename);

                                imgForExif.SetPropertyItem(imgForExif.PropertyItems[0]);

                                // Save rotation to file
                                imgForExif.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                                switch (Path.GetExtension(filename).ToLower())
                                {
                                case ".jpg":
                                    imgForExif.Save(filename, ImageFormat.Jpeg);
                                    break;

                                case ".png":
                                    imgForExif.Save(filename, ImageFormat.Png);
                                    break;

                                case ".bmp":
                                    imgForExif.Save(filename, ImageFormat.Bmp);
                                    break;

                                case ".gif":
                                    imgForExif.Save(filename, ImageFormat.Gif);
                                    break;
                                }
                            }

                            /*
                             * // Rotate display of image accordingly
                             * fType = GetRotateFlipTypeByExifOrientationData((int)orientation.Value[0]);
                             * if (fType != System.Drawing.RotateFlipType.RotateNoneFlipNone)
                             * {
                             *      imgForExif.RotateFlip(fType);
                             * }
                             */

                            // Get rotation angle accordingly
                            imageRotationAngle = GetBitmapRotationAngleByRotationFlipType(fType);
                        }
                    }

                    var img = new BitmapImage();
                    img.BeginInit();
                    img.CacheOption = BitmapCacheOption.OnLoad;

                    //img.UriSource = new Uri(filename);
                    imgStream.Seek(0, SeekOrigin.Begin); // seek stream to beginning
                    img.StreamSource = imgStream;        // load image from stream instead of file
                    img.EndInit();

                    // Rotate Image if necessary
                    TransformedBitmap transformBmp = new TransformedBitmap();
                    transformBmp.BeginInit();
                    transformBmp.Source = img;
                    RotateTransform transform = new RotateTransform(imageRotationAngle);
                    transformBmp.Transform = transform;
                    transformBmp.EndInit();
                    FullScreenImage.Source = transformBmp;
                    // Initialize rotation variable for next image
                    imageRotationAngle = 0;

                    //FullScreenImage.Source = img;
                    imageTimer.Start();

                    //********* NEW EXIF CODE **************
                    imgStream.Seek(0, SeekOrigin.Begin);
                    if (Path.GetExtension(filename).ToLower() == ".jpg") // load exif only for jpg
                    {
                        StringBuilder info = new StringBuilder();
                        info.AppendLine(filename + "\n" + (int)img.Width + "x" + (int)img.Height);
                        var decoder     = new JpegBitmapDecoder(imgStream, BitmapCreateOptions.IgnoreColorProfile | BitmapCreateOptions.IgnoreImageCache | BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
                        var bitmapFrame = decoder.Frames[0];
                        if (bitmapFrame != null)
                        {
                            BitmapMetadata metaData = (BitmapMetadata)bitmapFrame.Metadata.Clone();
                            if (metaData != null)
                            {
                                if (!String.IsNullOrWhiteSpace(metaData.DateTaken))
                                {
                                    info.AppendLine("Date taken: " + metaData.DateTaken);
                                }
                                if (!String.IsNullOrWhiteSpace(metaData.Title))
                                {
                                    info.AppendLine("Title: " + metaData.Title);
                                }
                                if (!String.IsNullOrWhiteSpace(metaData.Subject))
                                {
                                    info.AppendLine("Subject: " + metaData.Subject);
                                }
                                if (!String.IsNullOrWhiteSpace(metaData.Comment))
                                {
                                    info.AppendLine("User comment: " + metaData.Comment);
                                }
                            }
                        }
                        Overlay.Text = info.ToString();
                    }
                    else
                    {
                        Overlay.Text = filename + "\n" + (int)img.Width + "x" + (int)img.Height;
                    }
                }
            }
            catch
            {
                FullScreenImage.Source = null;
                ShowError("Can not load " + filename + " ! Screensaver paused, press P to unpause.");
            }
        }
Esempio n. 31
0
        public FileInfo ResizeImageFile(FileInfo image, Options options, AsyncCodeActivityContext context)
        {
            // Get the image codec info
            ImageCodecInfo CodecInfo = GetEncoderInfo("image/jpeg");

            //Save the bitmap as a JPEG file with quality level 75.
            System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Quality;
            EncoderParameter  encoderParameter     = new System.Drawing.Imaging.EncoderParameter(encoder, 100L);
            EncoderParameters encoderParameters    = new EncoderParameters();

            encoderParameters.Param[0] = encoderParameter;

            System.Drawing.Image  img    = null;
            System.Drawing.Bitmap bitmap = null;
            string savePath = string.Empty;

            try
            {
                img = System.Drawing.Image.FromFile(image.FullName);

                if (options.AutoRotate == true)
                {
                    var pi = img.PropertyItems.FirstOrDefault(p => p.Id == 0x0112);
                    if (pi != null)
                    {
                        switch (pi.Value[0])
                        {
                        case 6:
                            img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                            break;

                        case 8:
                            img.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                            break;

                        default:
                            break;
                        }
                    }
                }

                //set the width and height, using the original values if not specified
                int width  = options.Width == 0 ? img.Width : options.Width;
                int height = options.Height == 0 ? img.Height : options.Height;

                if (img.Width < img.Height)
                {
                    int tempWidth = width;
                    width  = height;
                    height = tempWidth;
                }

                bitmap = new System.Drawing.Bitmap(img, new System.Drawing.Size(width, height));

                //make sure the target directory exists. If not, create it!
                if (!Directory.Exists(options.TargetDirectory))
                {
                    Directory.CreateDirectory(options.TargetDirectory);
                }

                savePath = Path.Combine(options.TargetDirectory, image.Name);
                bitmap.Save(savePath, CodecInfo, encoderParameters);

                if (!string.IsNullOrWhiteSpace(savePath))
                {
                    return(new FileInfo(savePath));
                }

                return(null);
            }
            catch
            {
                throw new Exception
                      (
                          string.Format("Cannot resize '{0} as it is not a valid image file!", image.Name)
                      );
            }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }

                if (img != null)
                {
                    img.Dispose();
                }
            }
        }