日期:2014-05-17 浏览次数:21484 次
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>