如何将多个图片合并到一个文件流,一同输出到网页显示
现在我需要根据某条信息读出它所有的图片信息,然后为了不让别人直接看到真是图片地址是打算通过ashx直接resnponse输出图片,但问题是如何才能将多个图片同时输出显示?我始终只能显示出第一张图片.
下面是我写的部分代码,打算将多个图片写进一个文件流然后在一起输出,但结果还是只有第一张图,其中images是一个List<String>集合,存放的是图片的路径
response.ContentType = "image/jpeg"; var stream = new MemoryStream(); foreach (var img in images) { var imgbyte = File.ReadAllBytes(Sph.Common.Variables.ImgUploadRootPath + img.TrimStart('/')); stream.Write(imgbyte, 0, imgbyte.Length); } stream.Close(); response.BinaryWrite(stream.GetBuffer()); response.Flush();
private void ReduceImageSize(string filePath) { using (MemoryStream OrgImageMemory = new MemoryStream(File.ReadAllBytes(filePath))) { using (Image orgImage = Image.FromStream(OrgImageMemory)) { using (Bitmap result = new Bitmap(orgImage.Width / 2, orgImage.Height / 2)) { result.SetResolution(orgImage.HorizontalResolution / 2, orgImage.VerticalResolution / 2); using (Graphics graphics = Graphics.FromImage(result)) { graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; graphics.DrawImage(orgImage, 0, 0, result.Width, result.Height); } result.Save(filePath); } } } }
[解决办法]
页面
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:BoundField DataField="PersonName" /> <asp:ImageField DataImageUrlField="PersonId" DataImageUrlFormatString="ShowImage.aspx?id={0}"/> </Columns> </asp:GridView>