zoukankan      html  css  js  c++  java
  • 关于字节流和图像的转化

    //将image转换成byte[]数据
    private byte[] imageToByte(System.Drawing.Image _image)
    {
    MemoryStream ms = new MemoryStream();
    _image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    return ms.ToArray();
    }
    
    //将byte[]数据转换成image
    private System.Drawing.Image byteToImage(byte[] myByte)
    {
    MemoryStream ms = new MemoryStream(myByte);
    ms.Position = 0;
    System.Drawing.Image _Image = System.Drawing.Bitmap.FromStream(ms);
    ms.Close();
    return _Image;
    }
    本文实例讲述了asp.net实现图片以二进制流输出的两种方法。分享给大家供大家参考,具体如下:
    方法一: System.IO.MemoryStream ms
    = new System.IO.MemoryStream(); System.IO.Stream str = new FileUpload().PostedFile.InputStream; System.Drawing.Bitmap map = new System.Drawing.Bitmap(str); map.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); Response.ClearContent(); Response.ContentType = "image/gif"; Response.BinaryWrite(ms.ToArray());
    方法二:
    System.IO.FileStream fs = new System.IO.FileStream("Filename", System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] datas = new byte[fs.Length]; fs.Read(datas, 0, Convert.ToInt32(fs.Length)); fs.Close(); Response.OutputStream.Write(datas,0,Convert.ToInt32(fs.Length)); Response.End();
  • 相关阅读:
    java-学习8
    java-学习7
    java-学习6
    html----h1-6标签
    jquery.cookie介绍和用法
    java-学习5
    java-学习4
    Eclipse里的代码光标变成一个黑色块
    java-学习3(jdk-环境配置)
    箭头函数无法使用this的解决方法
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/10167984.html
Copyright © 2011-2022 走看看