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. 修改emlog表字段名称

    在em_twitter表中增加一个字段. ,添加一个字段isImportant alter table em_twitter add isImprotant ) not ; ,把字段isImprota ...

  2. linux下查找包含BOM头的文件和清除BOM头命令

    查找包含BOM头的文件,命令如下:   grep -r -I -l $'^\xEF\xBB\xBF' ./   这条命令会查找当前目录及子目录下所有包含BOM头的文件,并把文件名在屏幕上输出.   但 ...

  3. [译]AngularJS中几种Providers(Factory, Service, Provider)的区别

    原文: http://blog.xebia.com/2013/09/01/differences-between-providers-in-angularjs/ 什么是Provider? Angula ...

  4. Exception→"Source":"EntityFramework" "Message" :"更新条目时出错。有关详细信息,请参阅内部异常。"

    给一个数据库中类型为"datetime"的列赋值为 "DateTime.MinValue"...... 而// ::} But--01到9999-- :: 到 ...

  5. iOS 字符转换

    字典或者数组转化为nsstring NSArray *arr = [NSArray arrayWithObject:@"1"]; NSString *str = [arr JSON ...

  6. 在ashx中使用Server对象

    Server.MapPath() System.Web.HttpContext.Current.Server.MapPath()

  7. LUXURY 7

    A.Little Pony and Expected Maximum Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:% ...

  8. Python 集合set添加删除、交集、并集、集合操作符号

    在Python中集合set是基本数据类型的一种,它有可变集合(set)和不可变集合(frozenset)两种.创建集合set.集合set添加.集合删除.交集.并集.差集的操作都是非常实用的方法. 1. ...

  9. 【PHP面向对象(OOP)编程入门教程】12.重载新的方法(parent::)

    在学习PHP 这种语言中你会发现, PHP中的方法是不能重载的, 所谓的方法重载就是定义相同的方法名,通过“参数的个数“不同或“参数的类型“不 同,来访问我们的相同方法名的不同方法.但是因为PHP是弱 ...

  10. mysql explain用法和结果的含义

    重点是第二种用法,需要深入的了解. 先看一个例子: mysql> explain select * from t_order; +----+-------------+---------+--- ...