Solved

Display Images on Web Page

Posted on 2014-03-20
3
186 Views
Last Modified: 2014-03-25
OK, so there is NO picture Box in ASP.net...therefore I'm stuck!

I have this code that gets images from a Binary File that works great on my Windows Application into a Picture Box...how can I get this same code to work in ASP.net to an ImageBox?

   
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Image = GetImageFromFileStream(fs, 0, 4566)
End Sub

    Public Function GetImageFromFileStream(ByVal FileStream As System.IO.FileStream, ByVal Offset As Int32, ByVal Length As Int32) As System.Drawing.Image
        Dim Image As System.Drawing.Image = Nothing
        FileStream.Seek(Offset, System.IO.SeekOrigin.Begin)

        Dim BinaryReader As System.IO.BinaryReader = New System.IO.BinaryReader(FileStream)
        Dim ImageLength As System.Int32 = Length

        Dim Buffer(ImageLength - 1) As System.Byte
        Dim BytesRead As System.Int32 = 0

        BytesRead = FileStream.Read(Buffer, 0, Buffer.Length)

        If BytesRead = Buffer.Length Then
            Dim MemoryStream As System.IO.MemoryStream = New System.IO.MemoryStream(Buffer)
            Image = System.Drawing.Image.FromStream(MemoryStream).Clone
            MemoryStream.Close()
            MemoryStream.Dispose()
        End If

        Return Image
    End Function

Open in new window

0
Comment
Question by:smithmrk
3 Comments
 
LVL 22

Accepted Solution

by:
Mrunal earned 500 total points
ID: 39944363
declare img tag:

<img id="imgToDisplay" runat="server" />

Assign srouce property from code behind as:

imgToDisplay.src="data:image/png;base64,"+Convert.ToBase64String(imageBytes);

where imageBytes is a byte[]

Hope this helps you.
0
 

Author Closing Comment

by:smithmrk
ID: 39953415
Thanks!
I haven't had time to try it out, as I've got put on another project...but as soon as I get back to this I'll give it a try.

Mark
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Duplicate a row 2 46
ADO.NET ENTITY DATA MODEL 3 30
Receiving a string from a WebService Push 21 32
Error in JQuery 5 35
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now