69 lines
1.9 KiB
Plaintext
69 lines
1.9 KiB
Plaintext
<%@ WebHandler Language="C#" Class="dynimage" %>
|
|
|
|
using System;
|
|
using System.Web;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
public class dynimage : IHttpHandler
|
|
{
|
|
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
|
|
string imagetype = context.Request.QueryString["t"];
|
|
switch (imagetype)
|
|
{
|
|
case "flag":
|
|
{
|
|
|
|
Bitmap source = new Bitmap(context.Server.MapPath("~/graphics/FlagBlack16.png"));
|
|
|
|
int ARGB = int.Parse(context.Request.QueryString["argb"]);
|
|
Color NewColor = Color.FromArgb(ARGB);
|
|
swapcolor(Color.FromArgb(255, 0, 0, 0), NewColor, source);
|
|
|
|
context.Response.Clear();
|
|
context.Response.ContentType = "image/png";
|
|
|
|
using (MemoryStream stream = new MemoryStream())
|
|
{
|
|
source.Save(stream, ImageFormat.Png);
|
|
|
|
stream.WriteTo(context.Response.OutputStream);
|
|
}
|
|
|
|
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
public bool IsReusable {get{return false;}}
|
|
protected void swapcolor(Color oldColor, Color newColor, Bitmap baseImage)
|
|
{
|
|
if (newColor != oldColor)
|
|
{
|
|
|
|
int width = baseImage.Width;
|
|
int height = baseImage.Height;
|
|
|
|
int i, j;
|
|
for (i = 0; i < width; i++)
|
|
{
|
|
for (j = 0; j < height; j++)
|
|
{
|
|
Color pixelColor = baseImage.GetPixel(i, j);
|
|
|
|
//Replace each all black pixel with the chosen color
|
|
if (pixelColor == oldColor)
|
|
{
|
|
baseImage.SetPixel(i, j, newColor);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |