Esempio n. 1
0
        public void corpimg(string x, string y, string h, string w, string r, string filename, string clientID, string phone)
        {
            string rootPath = System.Configuration.ConfigurationManager.AppSettings.GetValues("RootPath").First().ToString();

            int w1 = Convert.ToInt32(w);
            int h1 = Convert.ToInt32(h);
            int x1 = Convert.ToInt32(x);
            int y1 = Convert.ToInt32(y);

            byte[] CropImage = Crop(rootPath + filename, w1, h1, x1, y1);
            using (MemoryStream ms = new MemoryStream(CropImage, 0, CropImage.Length))
            {
                ms.Write(CropImage, 0, CropImage.Length);
                using (SD.Image CroppedImage = SD.Image.FromStream(ms, true))
                {
                    if (File.Exists(rootPath + filename))
                        File.Delete(rootPath + filename);
                    string SaveTo = rootPath + filename;
                    CroppedImage.Save(SaveTo, CroppedImage.RawFormat);
                    //pnlCrop.Visible = false;
                    //pnlCropped.Visible = true;
                    //imgCropped.ImageUrl = "images/crop" + ImageName;
                }
            }

            //test image save code
            string FileName = rootPath + filename;
            byte[] ImageData;

            FileStream fs = new FileStream(rootPath + filename, FileMode.Open, FileAccess.Read);
            using (var image1 = Image.FromStream(fs))
            {
                var newWidth = (int)(image1.Width * 0.5);
                var newHeight = (int)(image1.Height * 0.5);
                var thumbnailImg = new Bitmap(newWidth, newHeight);
                var thumbGraph = Graphics.FromImage(thumbnailImg);
                thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
                thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
                thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
                var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
                thumbGraph.DrawImage(image1, imageRectangle);
                thumbnailImg.Save(rootPath + "New" + filename, image1.RawFormat);
                FileStream fs2 = new FileStream(rootPath + "New" + filename, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs2);
                ImageData = br.ReadBytes((int)fs2.Length);
                br.Close();
                fs2.Close();
            }
            fs.Close();
            File.Delete(rootPath + "New" + filename);
            //FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
            //BinaryReader br = new BinaryReader(fs);
            //ImageData = br.ReadBytes((int)fs.Length);
            //br.Close();
            //fs.Close();
            MySQLBusinessLogic bl = new MySQLBusinessLogic();
            bool ImgUpdate = false;
            if (ImageData.Length < 16777216)
            {
                int storeID = GetStoreIDbyPhone(phone);
                ImgUpdate = bl.UpdateStoreImage(ImageData, storeID, DateTime.Now);
            }
            else
                Clients.Client(clientID).storeImgPath("", "0");
            //end
            if (ImgUpdate == true)
            {
                updateImage(phone, clientID, "");
                File.Delete(rootPath + filename);
            }
            else
                Clients.Client(clientID).storeImgPath("", "0");

            //Clients.Client(clientID).storeImgPath(pt);
        }