Exemple #1
0
        public JsonResult Ekle(HttpPostedFileBase[] resimler, Urun model)
        {
            var cevap = Servis.Urun.Ekle(model);

            if (cevap.BasariliMi)
            {
                foreach (var item in resimler)
                {
                    using (ImageUploader uploader = new ImageUploader(item, "~/Content/images/urunler/orjinal"))
                    {
                        var uploadSonuc = uploader.UploadFile(model.SayfaYolu);
                        if (uploadSonuc.Status)
                        {
                            ThumbSettings settings = new ThumbSettings
                            {
                                NewFilePath = "~/Content/images/urunler/140",
                                OldFilePath = "~/Content/images/urunler/orjinal/" + uploadSonuc.FileName,
                                NewHeight   = 140,
                                NewWidth    = 140,
                            };
                            Resim rsm = new Resim();

                            rsm.UrunId   = model.Id;
                            rsm.BuyukYol = uploadSonuc.FileName;

                            rsm.KucukYol         = uploader.CreateThumb(settings);
                            settings.NewFilePath = "~/Content/images/urunler/300";
                            settings.NewHeight   = 300;
                            settings.NewWidth    = 300;
                            rsm.OrtaYol          = uploader.CreateThumb(settings);
                            Servis.Resim.Ekle(rsm);
                        }
                    }
                }
            }
            return(JSonuc(cevap));
        }
        // Hack framework için düzelt
        public string CreateThumb(ThumbSettings settings)
        {
            string oldFileName = HttpContext.Current.Server.MapPath(settings.OldFilePath);
            Image  img         = Image.FromFile(oldFileName);
            Bitmap bmp         = new Bitmap(width: settings.NewWidth, height: settings.NewHeight);

            using (Graphics gr = Graphics.FromImage((Image)bmp))
            {
                gr.SmoothingMode      = SmoothingMode.HighQuality;
                gr.CompositingQuality = CompositingQuality.HighQuality;
                gr.DrawImage(img, new Rectangle(0, 0, settings.NewWidth, settings.NewHeight));

                string[] fileArray = settings.OldFilePath.Split('/');
                string   fileNameWithExtensions = fileArray[fileArray.Length - 1];
                string   fileExtension          = System.IO.Path.GetExtension(fileNameWithExtensions);
                string   pureFileName           = fileNameWithExtensions.Replace(fileExtension, "");
                string   savedFileName          = pureFileName + settings.NewWidth + "x" + settings.NewHeight + FileExtension;
                string   saveAddress            = HttpContext.Current.Server.MapPath(settings.NewFilePath + "/" + savedFileName);

                bmp.Save(saveAddress, System.Drawing.Imaging.ImageFormat.Png);
                img.Dispose();
                return(savedFileName);
            }
        }