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 '

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several