devxlogo

ShowImage – Output an image as a binary stream to the Response object

ShowImage – Output an image as a binary stream to the Response object

' Output an image as a binary stream to the Response objectSub ShowImage(ByVal bmp As Bitmap)    ' Clear current content and set returned content type    HttpContext.Current.Response.Clear()    HttpContext.Current.Response.ContentType = "image/jpeg"    ' Save to the Response.OutputStream object    bmp.Save(HttpContext.Current.Response.OutputStream, _        Imaging.ImageFormat.Jpeg)    bmp.Dispose()    HttpContext.Current.Response.End()End Sub' Example:Private Sub Page_Load(ByVal sender As System.Object, _    ByVal e As System.EventArgs) Handles MyBase.Load    ' Create a bitmap with given width, height, and color depth.    Dim bmp As New Bitmap(400, 200, _        Drawing.Imaging.PixelFormat.Format16bppRgb565)    ' Get the underlying Graphics object.    Dim gr As Graphics = Graphics.FromImage(bmp)    ' Clear its background.    gr.Clear(Color.Red)    ' create a font    Dim fnt As New Font("Arial", 16, FontStyle.Regular, GraphicsUnit.Point)    Dim angle As Single    For angle = 0 To 360 Step 30        ' Reset coordinate transforms.        gr.ResetTransform()        ' Translate and rotate the coordinate system.        gr.TranslateTransform(200, 100)        gr.RotateTransform(angle)        ' Draw the (rotated) string.        gr.DrawString("   hello", fnt, Brushes.Yellow, 0, 0)    Next    ' Release resources.    fnt.Dispose()    gr.Dispose()    ShowImage(bmp)End Sub' Note: This code is taken from Francesco Balena's' "Programming Microsoft Visual Basic .NET" - MS Press 2002, ISBN 0735613753' You can read a free chapter of the book at ' http://www.vb2themax.com/HtmlDoc.asp?Table=Books&ID=101000

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist