http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 15947|回复: 4

[接口] 推荐一个asp.net的图片美化上传接口(美图秀秀)

[复制链接]
发表于 2014-8-25 12:45:14 | 显示全部楼层 |阅读模式
推荐一个asp.net的图片美化上传接口(美图秀秀)


这个其实是加载的美图秀秀的Api,使用的他们的JS和他们的FAlsh。编辑完之后可以直接上传到服务器

先来看看效果打开页面只有一个A链接
QQ截图20140825124106.jpg
单击这个上传图片


QQ截图20140825124113.jpg
选择两张图片

QQ截图20140825124156.jpg
好了之后单击保存就行了。

这只是之一,里面还有好多种比如头像编辑,和图片美化

QQ截图20140825124526.jpg

使用非常 方便
如果在家感觉他们的服务器不够快,可以使用自己的,只要下载Js类就行了。
代码如下
Html
[HTML] 纯文本查看 复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>美图WEB开放平台</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="http://open.web.meitu.com/sources/xiuxiu.js" type="text/javascript"></script>
    <script src="../Script/jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        function meituload() {
            //  1是美化图片,2拼图,5头像编辑,
            xiuxiu.embedSWF("altContent", 2, "100%", "100%");
            /*第1个参数是加载编辑器div容器,第2个参数是编辑器类型,第3个参数是div容器宽,第4个参数是div容器高*/
            xiuxiu.setUploadURL("http://www.sufeinet.com/stream.ashx"); //修改为您自己的上传接收图片程序
            xiuxiu.onInit = function () {
                xiuxiu.loadPhoto("http://open.web.meitu.com/sources/images/1.jpg");
            }
            xiuxiu.onUploadResponse = function (data) {
                //alert("上传响应" + data);  可以开启调试
            }
            xiuxiu._close = function () {
                $("#meitubox").hide(); //单关闭和取消按钮时
            }
        }
    </script>
    <style type="text/css">
        html, body { height: 100%; overflow: hidden; }
        body { margin: 0; }
    </style>
</head>
<body>
    <a id="ameitu" href="#">上传图片</a>
    <div id="meitubox" style="height: 100%;">
        <div id="altContent">
        </div>
    </div>
</body>
</html>


还有一个Handler文件
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Configuration;
using System.IO;
using System.Drawing;
using XiuXiuWeb.XiuXiuStream;

namespace XiuXiuWeb
{
    /// <summary>
    /// Summary description for stream
    /// </summary>
    public class stream : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            //config 配置节点可以将图片保存至指定目录,未配置将保存至 /XiuXiuUpload
            //<appSettings>
            //  <add key="XiuXiuImageSavePath" value="/upload"/>
            //</appSettings>
            string name = null;
            if (context.Request.TotalBytes > 0)
            {
                XiuXiuStreamImage img = new XiuXiuStreamImage(context);
                name = img.Save();
            }
            else
            {
                name = "非法访问";
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(name);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    namespace XiuXiuStream
    {

        /// <summary>
        /// 上传抽象类
        /// </summary>
        public abstract class XiuXiuImage
        {
            /// <summary>
            /// 基类保存
            /// </summary>
            /// <returns>返回保存路径+文件名</returns>
            public virtual string Save()
            {
                string fileName = this.GetFileName();
                if (null == fileName) return null;

                string root = HttpContext.Current.Server.MapPath(path);

                if (!Directory.Exists(root))
                {
                    Directory.CreateDirectory(root);
                }

                this.FileName = Path.Combine(root, fileName);
                string[] paths = { path, fileName };
                return string.Join("/", paths);
            }

            public XiuXiuImage()
            {
                path = path == null ? "/XiuXiuUpload" : path;
            }

            /// <summary>
            /// 确定上传类型
            /// </summary>
            protected bool IsUplodType
            {
                get
                {
                    string extension = this.GetExtension();
                    return ".jpg .gif .png .icon .bmp .tiff .wmf .emf .exif".IndexOf(extension) >= 0 ? true : false;
                }
            }
            private string _fileName = null;
            /// <summary>
            /// 最终保存路径
            /// </summary>
            protected string FileName
            {
                set { _fileName = value; }
                get { return _fileName; }
            }

            /// <summary>
            /// 配置文件路径 无配置上传到XiuXiuUpload
            /// </summary>
            protected string path = ConfigurationManager.AppSettings["XiuXiuImageSavePath"];

            /// <summary>
            /// 获取拓展名
            /// </summary>
            /// <returns></returns>
            protected abstract string GetExtension();

            /// <summary>
            /// 获取最终保存文件名
            /// </summary>
            /// <returns></returns>
            protected string GetFileName()
            {
                string extension = this.GetExtension();
                if (null == extension) return null;
                else
                {
                    string name = this.GetName();
                    string[] imgName = { "XiuXiu", name, extension };
                    return string.Join("", imgName);
                }
            }
            /// <summary>
            /// 获取保存文件名
            /// </summary>
            /// <returns></returns>
            private string GetName()
            {
                DateTime uploadTime = DateTime.Now;
                string[] times = { uploadTime.Year.ToString(), uploadTime.Month.ToString(), uploadTime.Day.ToString(),
                                 uploadTime.Hour.ToString(), uploadTime.Millisecond.ToString(), uploadTime.Second.ToString() };
                return string.Join("", times);
            }
        }
        /// <summary>
        /// Stream接收
        /// </summary>
        public sealed class XiuXiuStreamImage : XiuXiuImage
        {
            private MemoryStream stream = null;

            public XiuXiuStreamImage(HttpContext context)
            {
                int count = context.Request.TotalBytes;
                if (count > 0)
                {
                    if (count < 1024 * 1024 * 5)
                    {
                        byte[] bytes = context.Request.BinaryRead(context.Request.TotalBytes);
                        this.stream = new MemoryStream(bytes);
                    }
                   
                }
            }

            private Image File
            {
                get
                {
                    return this.stream == null ? null : Image.FromStream(this.stream);
                }
            }
            /// <summary>
            /// 保存图片,成功返回文件路径,失败null
            /// 非图片格式返回错误信息
            /// </summary>
            /// <returns>成功返回文件路径 失败null</returns>
            public override string Save()
            {
                if (!this.IsUplodType)
                {
                    this.stream.Dispose();
                    return "Only allowed to upload pictures.";
                }
                string returnName = base.Save();
                if (this.FileName != null)
                {
                    this.File.Save(this.FileName);
                    this.stream.Dispose();
                    return returnName;
                }
                return null;
            }

            protected override string GetExtension()
            {
                if (this.File != null)
                {
                    string fileExtension = this.File.RawFormat.ToString().Substring(14),
                           jpgExtension = System.Drawing.Imaging.ImageFormat.Jpeg.Guid.ToString(),
                           gifExtension = System.Drawing.Imaging.ImageFormat.Gif.Guid.ToString(),
                           pngExtension = System.Drawing.Imaging.ImageFormat.Png.Guid.ToString(),
                           iconExtension = System.Drawing.Imaging.ImageFormat.Icon.Guid.ToString(),
                           bmpExtension = System.Drawing.Imaging.ImageFormat.Bmp.Guid.ToString(),
                           tiffExtension = System.Drawing.Imaging.ImageFormat.Tiff.Guid.ToString(),
                           wmfExtension = System.Drawing.Imaging.ImageFormat.Wmf.Guid.ToString(),
                           emfExtension = System.Drawing.Imaging.ImageFormat.Emf.Guid.ToString(),
                           exifExtension = System.Drawing.Imaging.ImageFormat.Exif.Guid.ToString();
                    fileExtension = fileExtension.Substring(0, fileExtension.Length - 1);
                    if (fileExtension == jpgExtension)
                    {
                        return ".jpg";
                    }
                    else if (fileExtension == gifExtension)
                    {
                        return ".gif";
                    }
                    else if (fileExtension == pngExtension)
                    {
                        return ".png";
                    }
                    else if (fileExtension == iconExtension)
                    {
                        return ".icon";
                    }
                    else if (fileExtension == bmpExtension)
                    {
                        return ".bmp";
                    }
                    else if (fileExtension == tiffExtension)
                    {
                        return ".tiff";
                    }
                    else if (fileExtension == wmfExtension)
                    {
                        return ".wmf";
                    }
                    else if (fileExtension == emfExtension)
                    {
                        return ".emf";
                    }
                    else if (fileExtension == exifExtension)
                    {
                        return ".exif";
                    }
                }
                return null;
            }
        }
    }
}

需要的同志可以直接到官网上看看
http://open.web.meitu.com/products/

本帖被以下淘专辑推荐:



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-8-25 18:20:10 | 显示全部楼层
感谢您的无私奉献,真是帮了我的大忙了
发表于 2014-9-9 22:44:00 | 显示全部楼层
强烈支持楼主ing……
发表于 2016-4-14 11:40:25 | 显示全部楼层
请问版主!  有可以压缩 优化gif动态图的 API 或代码么?
发表于 2016-10-15 12:12:46 | 显示全部楼层
http://www.sufeinet.com/stream.ashx,这个stream.ashx是直接从美图秀秀api当下来的吗?我也是按照这么弄的,但是一直弹出MT0001!
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-3-29 13:43

© 2014-2021

快速回复 返回顶部 返回列表