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

    Hello,

    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()

    Image1.DataBind()


    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

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

    Posted 02 Feb 2011 Link to this post

    Solved.

    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:ScriptManagerProxy>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <div id="Div1" runat="server">
                <telerik:RadBinaryImage ID="Image1" runat="server" HttpHandlerUrl="~/MyHandler.axd" /> 
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

    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()
            'base.ProcessRequestInternal();
      
            Dim dataContainer As BinarImageDataContainer = ImagePersister.LoadImage()
            If dataContainer Is Nothing Then
                Return
            End If
      
            Dim image As Byte() = dataContainer.Data
      
            If image Is Nothing Then
                Return
            End If
      
            Dim response = HttpContext.Current.Response
            response.Clear()
      
            response.BinaryWrite(image)
            response.ContentType = "image/png"
      
            response.Flush()
        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

    ...do some stuff to create Bmp1
     
    Bmp1.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
    Image1.DataValue = stream.ToArray()
    Image1.DataBind()

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

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

    Hope it helps other vb user.

    René
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top