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. html5入门

    1.canvas标签 <canvas id="myCanvas"></canvas><!--canvas标签定义图形,比如图标和其他图像--> ...

  2. 使用BeanNameAutoProxyCreator实现spring的自动代理

    提到代理,我们可以使用ProxyBeanFactory,并配置proxyInterfaces,target和interceptorNames实现,但如果需要代理的bean很多,无疑会对spring配置 ...

  3. jquery 隐藏表单元素

    1.html <label for="lbl" >电压等级:</label> <input class="easyui-combobox&q ...

  4. 认识ATL窗口

    这是一个相当于“Hello world!”的任务,作为认识ATL,考查了其运作流程与机制. 环境:VS2008 创建:新建-项目-Win32项目-添加公用头文件用于(选择ATL). PS:注意新建项目 ...

  5. POJ 1905 Expanding Rods

                           Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1 ...

  6. UI第一节—— UILable

    1.首先说说怎么创建UI程序,打开xcode,选择Create  a new Xcode project.看如下截图 2,接下来就蹦出一个和写OC应用差不多的界面,不多解释了 3.我给工程取得名字就叫 ...

  7. 微信电脑版即将到来了 安装QQ浏览器微信版体验吧

    之前说过在手机上微信打字慢,tx最终还是想开了,最近TX邀请测试微信电脑版,想要尝鲜的朋友可以去exp.qq.com申请QQ浏览器微信版体验,不过体验将要结束了,相信正式版很快就要出来了.[微信网页版 ...

  8. 大型网站SEO优化策略框架

  9. centos systemctl指令

    # systemctl #输出已激活单元 # systemctl list-units #输出已激活单元 # systemctl --failed #输出运行失败的单元 # systemctl lis ...

  10. 超级强大的formValidator

    来源: http://www.cnblogs.com/wzmaodong http://www.neatstudio.com/show-73-1.shtml  (全) http://www.cnblo ...