Beispiel #1
0
        /// <param name="imgUrl">图片网络地址</param>
        /// <param name="formatType">剪裁方式</param>
        /// <param name="width">宽</param>
        /// <param name="high">高</param>
        public static ImgData doImgUpLoad(string imgUrl, ImgFormatType formatType = ImgFormatType.ScaleWith, int width = 500, int high = 800)
        {
            ImgData data = new ImgData();

            //开始处理图片相关
            if (!string.IsNullOrEmpty(imgUrl) && (imgUrl.StartsWith("http://") || imgUrl.StartsWith("https://")))
            {
                //开始上传图片
                ImgUploadRet imgRet = ImgUtil.UploadImag(imgUrl, new ImgFormat(1, formatType, width, high));
                if (imgRet.IsSuc)
                {
                    data.img_default  = imgRet.GetImgUrl(0); //本地化原尺寸地址
                    data.img_specify  = imgRet.GetImgUrl(1); //本地化后生成的指定规格 300*225后的地址
                    data.img_original = imgUrl;
                    //_logger.Error("----doImgUpLoad--- img_original: " + imgUrl + " img_default:" + data.img_default + " img_specify:"+data.img_specify);
                }
                else //失败
                {
                    data.img_default  = ""; //
                    data.img_specify  = ""; //
                    data.img_original = imgUrl;
                    _logger.Error("----doImgUpLoad--- Msg: " + imgRet.Msg + " 原地址:" + imgUrl);
                }
            }

            return(data);
        }
Beispiel #2
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        public ActionResult UploadImage()
        {
            HttpFileCollectionBase files = Request.Files;
            // bool isWideImage = Request["Select_ImgShowType"] == "1";
            Dictionary <string, string> result = new Dictionary <string, string>();
            HttpPostedFileBase          image1 = (HttpPostedFileBase)Request.Files["img1"];
            HttpPostedFileBase          image2 = (HttpPostedFileBase)Request.Files["img2"];
            HttpPostedFileBase          image3 = (HttpPostedFileBase)Request.Files["img3"];

            ImgFormat format = null;


            format = new ImgFormat(1, ImgFormatType.Spec, 140, 90);


            if (image1 != null)
            {
                ImgUploadRet imgRet = ImgUtil.UploadImag(image1, format);
                if (imgRet.IsSuc)
                {
                    result["img1"] = imgRet.GetImgUrl(1);
                }
            }
            if (image2 != null)
            {
                ImgUploadRet imgRet = ImgUtil.UploadImag(image2, format);
                if (imgRet.IsSuc)
                {
                    result["img2"] = imgRet.GetImgUrl(1);
                }
            }
            if (image3 != null)
            {
                ImgUploadRet imgRet = ImgUtil.UploadImag(image3, format);
                if (imgRet.IsSuc)
                {
                    result["img3"] = imgRet.GetImgUrl(1);
                }
            }

            return(Json(result));
        }