zoukankan      html  css  js  c++  java
  • WCF 服务器端 上传图片

            /// <summary>
            /// 上传图片
            /// </summary>
            /// <param name="name"></param>
            /// <param name="imageByte"></param>
            /// <returns></returns>
            public string UpLoadImage(string name, byte[] imageByte)
            {
                try
                {
                    //事务
                    using (RgFx.Data.DbTransactionScope scop = new RgFx.Data.DbTransactionScope())
                    {
                        using (MemoryStream stream = new MemoryStream(imageByte))
                        {
                            //保存路径
                            //string temps = HttpContext.Current.Server.MapPath("Images");
                            string temps = System.Web.Hosting.HostingEnvironment.MapPath("~/WCFServiceImages/" + name + "");
    
                            #region//二进制流转Image类型,(加水印) 第一种保存方式
                            System.Drawing.Image bgimage = System.Drawing.Image.FromStream(stream);
                            stream.Close();
                            //重新画,加水印
                            string addText = DateTime.Now.ToString();
                            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bgimage);
                            System.Drawing.Font f = new System.Drawing.Font("Verdana", 10);
                            System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
                            g.DrawString(addText, f, b, 0, 0);
                            g.Dispose();
                            bgimage.Save(temps);
                            bgimage.Dispose();
                            #endregion
    
                            #region//(不加水印把二进制流保存成文件) 第二种保存方式
                            using (FileStream fstream = File.Create(temps, imageByte.Length))
                            {
                                fstream.Write(imageByte, 0, imageByte.Length);   //二进制转换成文件
                            }
                            #endregion
                        }
                        //提交事务
                        scop.Complete();
                    }
                    return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(new { Statue = "OK", Message = "图片上传成功!" });
                }
                catch (Exception ex)
                {
                    return ex.ToString();
                }
            }
  • 相关阅读:
    VMware虚拟机安装
    软件测试面试题汇总
    软件测试步骤详解
    软件测试的分类&软件测试生命周期
    BUG 的生命周期
    Jmeter连接Mysql数据库
    Navicat连接Mysql报错:Client does not support authentication protocol requested by server;
    Mysql安装(win10 64位)
    Jmeter生成测试报告
    (转)Jmeter http请求之content-type
  • 原文地址:https://www.cnblogs.com/lushousong/p/3432997.html
Copyright © 2011-2022 走看看