編輯美化圖片,保存至本地,Adobe出品(支持IOS,android,web調用)免費插件

本例以web調用作爲例子,本插件支持主流瀏覽器,IE要9以上,移動設備,觸屏設備也支持,能自適應屏幕大小。javascript

使用效果:html

工具仍是很豐富的,編輯完成以後,能夠保存圖片至本地目錄。java

使用說明:jquery

1,須要在線註冊帳號,申請apikey,地址:https://creativesdk.adobe.com/docs/web,這個apikey在代碼調用時須要。這裏也有詳細的api文檔,其餘功能請參考文檔說明,不過文檔是英文的。web

2,要編輯的圖片必須有固定的地址,能夠被網絡訪問到。ajax

示例源代碼,以web調用爲例:api

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>汽車圖片編輯</title>
   <%-- <script src="js/CarPhotoEdit.js"></script>--%>
    <script src="../Scripts/jquery-1.7.1.js"></script>
    <script src="https://dme0ih8comzn4.cloudfront.net/js/feather.js"></script>
    <script type='text/javascript'>        
        //在線編輯圖片功能,第三方插件,徹底免費
        var featherEditor = new Aviary.Feather({
            apiKey: 'wanghuifang2008@yeah.net',//apikey能夠免費申請,https://creativesdk.adobe.com/docs/web/#/index.html
            apiVersion: 3,
            theme: 'dark', // Check out our new 'light' and 'dark' themes!
            tools: 'blemish',//這裏設置爲all,能夠顯示全部的工具
            initTool: 'blemish',//默認展開的工具
            language: 'zh_HANS',//簡體中文
            appendTo: '',          
            onSave: function (imageID, newURL) {
                //alert(newURL);
                $.ajax({
                    url: "ashx/CarInfo.ashx?type=DownloadCarPhoto&imgUrl=" + newURL + "&rand=" + Math.random(),
                    success: function (url) {
                        alert('保存成功');
                        var img = document.getElementById(imageID);
                        img.src = url;
                    },
                    error: function () {
                        alert('error')
                    }
                });
                
            },
            onError: function (errorObj) {
                alert(errorObj.message);
            }
        });
        function launchEditor(id, src) {
            featherEditor.launch({
                image: id,
                url: src
            });
            return false;
        }
</script>
</head>
<body>
    <form id="form1" runat="server">
   <div id='injection_site'></div>
<%--http://images.aviary.com/imagesv5/feather_default.jpg--%>
<%--http://car0.autoimg.cn/car/upload/2015/1/8/v_20150108092921264345010.jpg--%>
<img id='image1' src='http://images.aviary.com/imagesv5/feather_default.jpg'/>

<!-- Add an edit button, passing the HTML id of the image and the public URL of the image -->
<p><input type='image' src='' value='Edit photo' onclick="return launchEditor('image1', 'http://images.aviary.com/imagesv5/feather_default.jpg');" /></p>

    </form>
</body>
</html>
CarInfo.ashx功能是下載處理好的圖片到本地,代碼參考(來自網絡):
/// <summary>
    /// 下載遠程圖片保存到本地
    /// </summary>
    /// <param name="savedir">本地保存路徑</param>
    /// <param name="imgpath">遠程圖片文件</param>
    /// <returns></returns>
    public string downRemoteImg(string savedir, string imgpath)
    {
        if (string.IsNullOrEmpty(imgpath))
            return string.Empty;
        else
        {
            string imgName = string.Empty;
            string imgExt = string.Empty;
            string saveFilePath = string.Empty;
            imgName = imgpath.Substring(imgpath.LastIndexOf("/"), imgpath.Length - imgpath.LastIndexOf("/"));
            imgExt = imgpath.Substring(imgpath.LastIndexOf("."), imgpath.Length - imgpath.LastIndexOf("."));

            saveFilePath = System.Web.HttpContext.Current.Server.MapPath(savedir);
            if (!Directory.Exists(saveFilePath))
                Directory.CreateDirectory(saveFilePath);

            try
            {
                WebRequest wreq = WebRequest.Create(imgpath);
                wreq.Timeout = 10000;
                HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
                Stream s = wresp.GetResponseStream();
                System.Drawing.Image img;
                img = System.Drawing.Image.FromStream(s);
                switch (imgExt.ToLower())
                {
                    case ".gif":
                        img.Save(saveFilePath + imgName, ImageFormat.Gif);
                        break;
                    case ".jpg":
                    case ".jpeg":
                        img.Save(saveFilePath + imgName, ImageFormat.Jpeg);
                        break;
                    case ".png":
                        img.Save(saveFilePath + imgName, ImageFormat.Png);
                        break;
                    case ".icon":
                        img.Save(saveFilePath + imgName, ImageFormat.Icon);
                        break;
                    case ".bmp":
                        img.Save(saveFilePath + imgName, ImageFormat.Bmp);
                        break;
                }

                img.Dispose();
                s.Dispose();

                return savedir + imgName;
            }
            catch
            {
                return imgpath;
            }
        }
    }
相關文章
相關標籤/搜索