自定义HTTP处理

Amboise

ID: 1
地点: Amboise
国家: France
Amboise

ID: 2
地点: Amboise
国家: France
Amboise

ID: 3
地点: Amboise
国家: France
Amboise

ID: 4
地点: Amboise
国家: France
Blois

ID: 5
地点: Blois
国家: France
Blois

ID: 6
地点: Blois
国家: France
Chaumont

ID: 7
地点: Chaumont
国家: France
Chaumont

ID: 8
地点: Chaumont
国家: France
描述

这个DEMO使用HttpHandlerUrl属性指定一个HTTP处理程序来处理图像。

示例:

  • 设置 HttpHandlerUrl属性为 "CustomBinaryImageHandler.ashx".
  • 类CustomBinaryImageHandler继承自C1BinaryImageHandler类(类:C1.Web.Wijmo.Controls.C1BinaryImage.C1BinaryImageHandler)
    并重写ProcessImageData方法来自定义图像:

    public class CustomBinaryImageHandler : C1BinaryImageHandler
    {
        public override C1BinaryImageData ProcessImageData(C1BinaryImageData imageData)
        {
            using (var outStream = new System.IO.MemoryStream())
            using (var inStream = new System.IO.MemoryStream(imageData.Data))
            using (var image = Bitmap.FromStream(inStream))
            {
                var newImage = AddWatermark(image);
                newImage.Save(outStream, ImageFormat.Png);
                imageData.Data = outStream.ToArray();
                imageData.MimeType = "image/png";
                imageData.ImageFileName += "_Watermark";
            }
    
            return base.ProcessImageData(imageData);
        }
    
        private Image AddWatermark(Image image)
        {
            var watermarkString = "ComponentOne";
            var font = new Font("Arial", 8F, FontStyle.Regular);
            var newImage = new Bitmap(image.Width, image.Height);
    
            using (var g = Graphics.FromImage(newImage))
            {
                g.DrawImage(image, new Point(0, 0));
                g.DrawString(watermarkString, font, new SolidBrush(Color.White), new PointF(2, newImage.Height - font.Height - 2));
            }
    
            return newImage;
        }
    }
                

文档