CÁC GIẢI PHÁP LẬP TRÌNH C# - Trang 268

268
Chương 7: ASP.NET và Web Form

Response.Redirect(Request.Url + "?image=" +

Server.UrlEncode("This is a test image"));

}

else {

text = Server.UrlDecode(Request.QueryString["image"]);

}

// Tạo một hình bitmap trong-bộ-nhớ

// (rộng 300 pixel và cao 200 pixel).

int width = 300, height = 200;

Bitmap bitmap = new Bitmap(width, height);

// Lấy graphics context của hình bitmap.

Graphics graphics = Graphics.FromImage(bitmap);

// Thiết lập màu nền và chất lượng hình.

// Màu này sẽ trở thành đường viền.

graphics.Clear(Color.OrangeRed);

graphics.SmoothingMode = SmoothingMode.AntiAlias;

// Vẽ một hình chữ nhật.

graphics.FillRectangle(new SolidBrush(Color.Olive), 5, 5,

width - 10, height - 10);

// Chọn font và alignment cho text.

Font fontBanner = new Font("Verdana", 24, FontStyle.Bold);

StringFormat stringFormat = new StringFormat();

stringFormat.Alignment = StringAlignment.Center;

stringFormat.LineAlignment = StringAlignment.Center;

// Vẽ text.

graphics.DrawString(text, fontBanner,

new SolidBrush(Color.LightYellow),

new Rectangle(0, 0, width, height), stringFormat);