Reputation: 306
I am wanting to show the new bitmap image thats been created. Not save it.
Im using bitmap with graphics in C# and im hoping to return the new image without having to save a new image.
C#
private void GenerateBanner( string titleText ) {
Bitmap bannerSource = new Bitmap( DefaultBannerPath );
//bannerSource.Save( PhysicalBannerPath );
RectangleF rectf = new RectangleF( 430, 50, 650, 50 );
using (Graphics g = Graphics.FromImage(bannerSource))
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
g.DrawString(titleText, new Font("Bradley Hand ITC", 100, FontStyle.Bold), Brushes.White, rectf);
//bannerSource.Save( PhysicalBannerPath );
}
}
Upvotes: 0
Views: 217
Reputation: 4889
To return this image from an ASPX page (can be used as img src
in HTML), you'll need to use a MemoryStream
and convert it to byte[]
; then use the Response.BinaryWrite
method:
byte[] bytes;
using (var stream = new System.IO.MemoryStream())
{
bannerSource.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
bytes = stream.ToArray();
}
Response.ContentType = "image/jpeg";
Response.Clear();
Response.BinaryWrite(bytes);
Response.End();
Upvotes: 2