C# 使用HttpResponse将字节[]作为file.jpg添加到ZipFile
我已成功截取下载的代码:C# 使用HttpResponse将字节[]作为file.jpg添加到ZipFile,c#,asp.net,httpresponse,C#,Asp.net,Httpresponse,我已成功截取下载的代码: byte[] bytes; bytes = Convert.FromBase64String(lehrling.passfoto); Response.Clear(); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "image/jpg"; Response.AddHeader("content-disposition", "attachment; fil
byte[] bytes;
bytes = Convert.FromBase64String(lehrling.passfoto);
Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/jpg";
Response.AddHeader("content-disposition", "attachment; filename=" + lehrling.vorname + "." + lehrling.nachname + ".jpeg");
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.End()
for (int i = 0; i < anzahlBilder; i++)
{
//My Code here
}
Response.End()
这个很好用。我从中得到一个jpeg文件。现在:
我创建了一个for循环,为每个bytearray执行上面显示的代码:
byte[] bytes;
bytes = Convert.FromBase64String(lehrling.passfoto);
Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/jpg";
Response.AddHeader("content-disposition", "attachment; filename=" + lehrling.vorname + "." + lehrling.nachname + ".jpeg");
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.End()
for (int i = 0; i < anzahlBilder; i++)
{
//My Code here
}
Response.End()
for(int i=0;i
我从其他地方得到了安扎尔比尔德。这对我的问题不重要。我将Response.End()
放在for循环之外,因为否则它会在下载1image
后结束
到Zip:
byte[] bytes;
bytes = Convert.FromBase64String(lehrling.passfoto);
Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/jpg";
Response.AddHeader("content-disposition", "attachment; filename=" + lehrling.vorname + "." + lehrling.nachname + ".jpeg");
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.End()
for (int i = 0; i < anzahlBilder; i++)
{
//My Code here
}
Response.End()
现在我想创建一个.Zip文件,其中包含我的所有图像。我不知道怎么做。有什么建议吗?使用
您需要向程序集“System.IO.Compression.FileSystem.dll”添加dll引用并导入命名空间
System.IO.Compression
在顶端
ZipFile zipFile = new ZipFile();
for(int i = 0; i < anzahlBilder; i++)
{
using (MemoryStream ms= new MemoryStream(Convert.FromBase64String(lehrling.passfoto)))
{
Image userImage = Image.FromStream(ms);
userImage.Save(ms, ImageFormat.Jpeg);
ms.Seek(0, SeekOrigin.Begin);
byte[] imageData = new byte[ms.Length];
ms.Read(imageData, 0, imageData.Length);
zipFile.AddEntry(lehrling.vorname + "." + lehrling.nachname + ".jpeg", imageData);
}
}
zipFile.Save(Response.OutputStream);
ZipFile-ZipFile=new-ZipFile();
对于(int i=0;i
对lehrling.passfoto
和lehrling.vorname+“+lehrling.nachname+”.jpeg“
进行必要的更改以使其正常工作。
您需要向程序集“System.IO.Compression.FileSystem.dll”添加dll引用并导入命名空间
System.IO.Compression
在顶端
ZipFile zipFile = new ZipFile();
for(int i = 0; i < anzahlBilder; i++)
{
using (MemoryStream ms= new MemoryStream(Convert.FromBase64String(lehrling.passfoto)))
{
Image userImage = Image.FromStream(ms);
userImage.Save(ms, ImageFormat.Jpeg);
ms.Seek(0, SeekOrigin.Begin);
byte[] imageData = new byte[ms.Length];
ms.Read(imageData, 0, imageData.Length);
zipFile.AddEntry(lehrling.vorname + "." + lehrling.nachname + ".jpeg", imageData);
}
}
zipFile.Save(Response.OutputStream);
ZipFile-ZipFile=new-ZipFile();
对于(int i=0;i
对
lehrling.passfoto
和lehrling.vorname+“+lehrling.nachname+”.jpeg“
进行必要的更改,以使其正常工作。?是的,但在我的示例中,作为参数写什么?你能提供一个代码示例吗?是的,但是在我的示例中,作为参数我应该写什么呢?你能提供一个代码示例吗?谢谢你的回答,我可以创建一个ZipFile实例。它说它必须转换为System.i Responsible,知道为什么吗?哪一行?我应该设置什么为tempstream?也不工作,它说它不能这样定义确切的消息是什么?谢谢你的回答,我可以创建一个ZipFile实例thoe。它说它必须转换为系统。我负责,知道为什么吗?哪一行?我应该设置什么为tempstream?也不工作,它说它不能这样定义确切的消息是什么?