Created
October 4, 2009 05:58
-
-
Save dvhthomas/201182 to your computer and use it in GitHub Desktop.
Create image dynamically for testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static MemoryStream CreateTempImage(int width, int height) | |
{ | |
using (var image = new Bitmap(width, height, PixelFormat.Format32bppArgb)) | |
{ | |
string text = String.Format("{0:s}", DateTime.Now); | |
Graphics graphics = Graphics.FromImage(image); | |
var brush = new SolidBrush(Color.Red); | |
graphics.FillRectangle(brush, 0, 0, image.Width, image.Height); | |
var font = new Font("Arial", 18, FontStyle.Bold); | |
var textBrush = new SolidBrush(Color.White); | |
var format = new StringFormat { Alignment = StringAlignment.Center }; | |
graphics.DrawString(text, font, textBrush, width / 2, height / 2, format); | |
var stream = new MemoryStream(); | |
image.Save(stream, ImageFormat.Bmp); | |
stream.Position = 0; | |
return stream; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment