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. Jedis 例子(demo)大全

    第一步:到git下载jedis源码,如果你用maven或者gradle,那么直接下官方的即可,地址:https://github.com/xetorthio/jedis:如果你用ant,下载这个:ht ...

  2. wamp包--如何导出sql

    在windows下安装wamp,如果不想用phpmyadmin工具和其他工具,如何导出自己想要的sql呢. 比如:我想导出blogyaf库,可以从以下步骤进行操作. 1,进入到wamp的mysql安装 ...

  3. PHP中获取内网用户MAC地址(WINDOWS/linux)的实现代码

    做一个内网根据MAC地址自动登录的应用,在WINDOW 2003可以正常使用,函数如下   复制代码 代码如下: function ce_getmac() { if(PHP_OS == 'WINNT' ...

  4. git SSH keys

    An SSH key allows you to establish a secure connection between your computer and GitLab. Before gene ...

  5. JCarouselLite--帮助文档

    jcarousellite是一款jquery插件,可以控制文档元素滚动,丰富的参数设置可以控制滚动的更多细节,是一款不可多得的滚动插件. ------------------ 官网地址:http:// ...

  6. CodeForces 55D Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  7. 跨域攻击xss

    要完全防止跨域攻击是很难的,对于有些站点是直接 拦截跨域的访问,在你从本站点跳转到其他站点时提醒,这算是一种手段吧. 而跨域攻击的发起就是在代码(包括html,css,js或是后台代码,数据库数据)里 ...

  8. 开发板支持wifi

    参考网址: http://wangye.org/blog/archives/845/ http://blog.csdn.net/lme525/article/details/37762519  htt ...

  9. android GestureDetector 手势基础

    1. 当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouch(Vi ...

  10. HDU 5122 K.Bro Sorting(2014北京区域赛现场赛K题 模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5122 解题报告:定义一种排序算法,每一轮可以随机找一个数,把这个数与后面的比这个数小的交换,一直往后判 ...