首页 > 其他 > 详细

从流获取缩略图

时间:2015-05-26 17:45:49      阅读:208      评论:0      收藏:0      [点我收藏+]

 /// <summary>
        /// 从流获取缩略图
        /// </summary>
        /// <param name="filePathWithFileName"></param>
        private void CreateFavoriteThumb(string filePathWithFileName)
        {
            if (Request.InputStream == null || Request.InputStream.Length == 0)
            {
                throw new Exception("没有接收到缩略图文件流");
            }

            MemoryStream ms = null;
            try
            {
                using (ms = new MemoryStream())
                {
                    byte[] buffer = new byte[Request.InputStream.Length];
                    int read;
                    while ((read = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    Bitmap b = new Bitmap(ms);
                    b.Save(filePathWithFileName);
                }
            }
            catch
            {
                throw new Exception("缩略图保存失败");
            }
            finally
            {
                if (ms != null)
                {
                    ms.Flush();
                    ms.Close();
                    ms = null;
                }
            }
        }

从流获取缩略图

原文:http://www.cnblogs.com/zhtbk/p/4530745.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!