Howto display Image from Bitmap Object

2 posts, 0 answers
  1. Rene
    Rene avatar
    5 posts
    Member since:
    Feb 2011

    Posted 02 Feb 2011 Link to this post


    please give me some information about loading a bitmap from memory.

    I have tried it with


    Dim stream As New System.IO.MemoryStream


    Bmp1.Save(stream, System.Drawing.Imaging.ImageFormat.Png)

    Image1.DataValue = stream.GetBuffer()


    in CodeBehind. Bmp1 is a bitmap that is created and modified in code before.

    No image is displayed. What do I have to do? I think I have not already understood the idea of binary image.

    Thanks in advance

  2. Rene
    Rene avatar
    5 posts
    Member since:
    Feb 2011

    Posted 02 Feb 2011 Link to this post


    The problem is solved with following code in vb:

    1) Necessary to tell RadBinaryImage to add your own HTTPHandler; in my code it's inside of an UpdatePanel

    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="SCEImage1.ascx.vb" Inherits="SCE.SCEImage1" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register src="Canvas.ascx" tagname="Canvas" tagprefix="uc1" %>
    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <div id="Div1" runat="server">
                <telerik:RadBinaryImage ID="Image1" runat="server" HttpHandlerUrl="~/MyHandler.axd" /> 

    2) The custom HTTP handler is a standard class file with the following definition

    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Web
    Imports Telerik.Web.UI
    Public Class MyHandler
        Inherits RadBinaryImageHandler
        Protected Overrides Sub ProcessRequestInternal()
            Dim dataContainer As BinarImageDataContainer = ImagePersister.LoadImage()
            If dataContainer Is Nothing Then
            End If
            Dim image As Byte() = dataContainer.Data
            If image Is Nothing Then
            End If
            Dim response = HttpContext.Current.Response
            response.ContentType = "image/png"
        End Sub
    End Class

    3) The code to bind the memory bitmap to BinaryImage control. It is a need to save Bitmap in same format like handled in HTTPHandler above

    Dim stream As New System.IO.MemoryStream, Bmp1 As Bitmap some stuff to create Bmp1
    Bmp1.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
    Image1.DataValue = stream.ToArray()

    4) Entry in web.config for the need of another HTTPHandler

    <add path="MyHandler.axd" type="MyHandler" verb="*" validate="false" />

    Hope it helps other vb user.

  3. DevCraft R3 2016 release webinar banner
Back to Top