zoukankan      html  css  js  c++  java
  • 从流获取缩略图

     /// <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;
                    }
                }
            }

  • 相关阅读:
    Java8实战之Stream流式操作
    类、对象、引用
    java对象的四种引用:强引用、软引用、弱引用和虚引用
    《将博客搬至CSDN》
    **JAVA参数传递方式 (按值传递与引用传递区别)
    JavaWeb--ServletContext
    HttpSessionListener的用法
    SpringMVC优雅的获取HttpSevletRequest及HttpServletResponse简录
    setnx
    JVM命令工具开发
  • 原文地址:https://www.cnblogs.com/zhtbk/p/4530745.html
Copyright © 2011-2022 走看看