1:  Response.BinaryWrite() 其实就是和输出文字一样 只是图片是流的形式;

        delegate long myDel(int first, int second);
FileStream fs;
byte[] _byte;
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
fs = new FileStream(Server.MapPath("~/file/") + HttpUtility.UrlDecode("你好.jpg"), FileMode.Open);
_byte = new byte[fs.Length];
IAsyncResult ir = fs.BeginRead(_byte, , (int)fs.Length, null, null);
fs.Read(_byte, , fs.EndRead(ir));
fs.Close();
Response.BinaryWrite(_byte); }

2:循环

        protected void Button1_Click(object sender, EventArgs e)
{
string filePath = Server.MapPath("~/file/") + HttpUtility.UrlDecode("你好.jpg");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("你好.jpg", Encoding.UTF8));
//FileInfo fi = new FileInfo(filePath);
//Response.WriteFile(fi.FullName);
//Response.End(); int length = ;
byte[] arr = new byte[ * * ];
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
length = fs.Read(arr, , arr.Length);
}
byte[] arrNew = new byte[length];
System.Buffer.BlockCopy(arr, , arrNew, , length);
Response.BinaryWrite(arrNew);
}
        public static void ResponseFile(string filePath, HttpContext context, bool hasfileName)
{
Stream iStream = null;
byte[] buffer = new Byte[];
int length;
long dataToRead;
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(Path.GetFileName(filePath), Encoding.UTF8));
using (iStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
dataToRead = iStream.Length;
while (dataToRead > )
{
if (context.Response.IsClientConnected)
{
length = iStream.Read(buffer, , );
context.Response.OutputStream.Write(buffer, , length);
context.Response.Flush();
buffer = new Byte[];
dataToRead = dataToRead - length;
}
else
{
dataToRead = -;
}
}
}

c#图片输出的更多相关文章

  1. 使用IExport进行图片输出出现File creation error

    使用IExport进行图片输出(.JPG)时,出现如下异常File creation error.   在ESRI.ArcGIS.Output.ExportJPEGClass.FinishExport ...

  2. 【PDF单页转化为图片输出 注意:英文或图片类的PDF可转化,中文抛异常】

    public static void main(String[] args) throws IOException { /** * PDF单页转化为图片输出 注意:英文或图片类的PDF可转化,中文抛异 ...

  3. webpack2.0 css文件引入错误解决及图片输出在根目录配置问题

    webpack引入css文件,main.js内容如下 import Vue from 'vue'; import App from './App.vue'; import Mint from 'min ...

  4. Struts2将图片输出到页面

            在做CRUD的过程中,添加页面是个表单,表单里面有一项是上传头像文件.这样表单提交后,头像文件上传了. 但这个文件存的地址是本地硬盘的一个文件夹.在编辑页面要做这个头像的回显的话,就需 ...

  5. freemarker 图片输出、多张图片输出(图片重复原因及解决)

    单张图片显示: 先写好word格式的文档,在其中插入一张图片,然后重命名为ftl,再用编辑器打开,把图片那一段base64信息用freemarker表达式替换掉. 之后把图片的信息输出到模板即可. 多 ...

  6. Mac OS X下GnuPlot的安装和配置(无法set term png等图片输出)

    今天使用gitstats分析git repo的活动信息,发现其内部使用gnuplot,结果发现无法生成png图片,进入gnuplot的shell发现无法设置png格式输出.如下 gnuplot> ...

  7. 图片输出onerror事件

    <img src=".<?php echo $img[0];?>" onerror="this.src='img/zanwu.jpg'" st ...

  8. Lodop图片输出ADD_PRINT_IMAGE 有白边

    ADD_PRINT_IMAGE输出图片,如果使用img标签(即超文本<img标签),是超文本,无论是相对路径,网络图片,还是base64,都可能有白边,这可能和超文本解析有关.ADD_PRINT ...

  9. django2 显示图片 输出图片

    使用笨办法,指向图片的路径,然后输出图片. 首先路由设置: # 查看图片 path('tu/', ShowTuView.as_view(), name='image') 视图代码: import os ...

随机推荐

  1. Myeclipse如何关联源码

    Myeclipse版本:Myeclipse2014 关联源码前要下载对应的源码,如本例的dom4j-1.6.1.jar,则去下载对应的源码dom4j-1.6.1.zip 如果做的是web项目,就要将该 ...

  2. 使用MVVM框架(avalonJS)进行快速开发

    背景 在运营活动开发中,因为工作的重复性很大,同时往往开发时间短,某些情况下也会非常紧急,导致了活动开发时间被大大压缩,同时有些活动逻辑复杂,数据或者状态变更都需要手动渲染,容易出错,正是因为这些问题 ...

  3. [译]git reflog

    用法 git reflog 显示整个本地仓储的commit, 包括所有branch的commit, 甚至包括已经撤销的commit, 只要HEAD发生了变化, 就会在reflog里面看得到. git ...

  4. 繁华模拟赛day8 字典序

    /* 这个题要我们求一个字典序,字符串给出的顺序,会对字母的字典序前后相对顺序进行限定,如何用来表示这种限定,我们注意到这种一个之后接着一个,只有先输出他前面的才能输出他,很明显就是拓扑排序,最小方案 ...

  5. 如何编译Apache Hadoop2.6.0源代码

    如何编译Apache Hadoop2.6.0源代码 1.安装CentOS 我使用的是CentOS6.5,下载地址是http://mirror.neu.edu.cn/centos/6.5/isos/x8 ...

  6. Swift2.1 语法指南——访问控制

    原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...

  7. xcode7 NSAppTransportSecurity

    在Info.plist中添加  NSAppTransportSecurity 类型  Dictionary Dictionary 下添加  NSAllowsArbitraryLoads 类型 Bool ...

  8. git之create local reposition(创建本地仓库)

    1.创建名为git-reposition的仓库 mkdir home/sunjf/git-reposition 注:home/sunjf可以指定为你想要的路径下面 2.初始化仓库 cd ~/git-r ...

  9. canvas对象arc函数的使用-遁地龙卷风

    (-1)写在前面 我用的是chrome49 <canvas id="lol" height="300"></canvas> (1)详细介 ...

  10. BZOJ4439——[Swerc2015]Landscaping

    0.题目: FJ有一块N*M的矩形田地,有两种地形高地(用'#'表示)和低地(用'.'表示) FJ需要对每一行田地从左到右完整开收割机走到头,再对每一列从上到下完整走到头,如下图所示   对于一个4* ...