Пример #1
0
        public JsonResult UploadPictures()
        {
            if (Request.Files["FileData"] != null && !string.IsNullOrEmpty(Request["GroupID"]))
            {
                var         t = Request.Files["FileData"].InputStream;
                string      fileName = Request.Files["FileData"].FileName;
                string      extName = Path.GetExtension(fileName);
                Image       img = Image.FromStream(t);
                ImageFormat imgFormat = ImageHelper.GetImageFormat(extName);
                byte[]      bt = ImageHelper.ImageToBytes(img, imgFormat);
                int         height = img.Height;
                int         width = img.Width;
                int         limitedHeight = !string.IsNullOrEmpty(Request["ThumbHeight"]) ? Convert.ToInt32(Request["ThumbHeight"]) : 60;
                int         thumbHeight, thumbWidth;
                byte[]      btThumb = null;
                if (height > limitedHeight)
                {
                    thumbHeight = limitedHeight;
                    thumbWidth  = thumbHeight * width / height;
                    Image imgThumb = img.GetThumbnailImage(thumbWidth, thumbHeight, null, IntPtr.Zero);
                    btThumb = ImageHelper.ImageToBytes(imgThumb, imgFormat);
                }
                else
                {
                    btThumb = bt;
                }
                if (height > 538)
                {
                    int   imgWidth = 538 * width / height;
                    Image imgThumb = ZoomImage(img, 538, imgWidth);
                    bt = ImageHelper.ImageToBytes(imgThumb, imgFormat);
                }
                S_I_NewsImage newsImage = new S_I_NewsImage();
                string        groupID   = Request["GroupID"];
                newsImage.ID             = Formula.FormulaHelper.CreateGuid();
                newsImage.GroupID        = Request["GroupID"];
                newsImage.PictureName    = fileName;
                newsImage.PictureEntire  = bt;
                newsImage.PictureThumb   = btThumb;
                newsImage.SortIndex      = entities.Set <S_I_NewsImage>().Where(c => c.GroupID == groupID).Count();
                newsImage.CreateTime     = DateTime.Now;
                newsImage.CreateUserID   = Formula.FormulaHelper.GetUserInfo().UserID;
                newsImage.CreateUserName = Formula.FormulaHelper.GetUserInfo().UserName;

                entities.Set <S_I_NewsImage>().Add(newsImage);
                entities.SaveChanges();

                return(Json(new { ID = newsImage.ID, GroupID = newsImage.GroupID, PictureName = newsImage.PictureName, SortIndex = newsImage.SortIndex }));
            }
            else
            {
                return(Json(string.Empty));
            }
        }
Пример #2
0
        public ActionResult GetPicThumb(string groupID, string id, int?width, int?height)
        {
            S_I_NewsImage newsImage = GetNewsImage(groupID, id);

            if (newsImage != null)
            {
                if (newsImage.PictureThumb != null)
                {
                    return(new ImageActionResult(newsImage.PictureThumb, width, height));
                }
            }
            return(Content(string.Empty));
        }
Пример #3
0
        private S_I_NewsImage GetNewsImage(string groupID, string id)
        {
            S_I_NewsImage model = null;

            groupID = groupID == null ? "" : groupID;
            if (Formula.Helper.CacheHelper.Get(NewsImagePrefix + groupID) != null)
            {
                List <S_I_NewsImage> list = (List <S_I_NewsImage>)Formula.Helper.CacheHelper.Get(NewsImagePrefix + groupID);
                model = list.Find(t => t.ID == id);
            }
            else
            {
                model = entities.Set <S_I_NewsImage>().Find(id);
            }
            return(model);
        }