Try this -

Public Sub ShowImageTN()
       Dim lobjProduct As New Product
       lobjProduct.LoadByPrimaryKey(m_strKey)
       Dim bmpNew As Bitmap
       Dim imageNew As Image
       Dim objGraphics As Graphics
       Dim image As Image
       If lobjProduct.Product_Image.Length <= 1 Then
           Exit Sub
       End If
       Dim bmp As New Bitmap(New
System.IO.MemoryStream(lobjProduct.Product_Image))
       'Dim bmp As New Bitmap(New System.IO.MemoryStream(gImageBytes))
       image = bmp
       Try
           objGraphics = Graphics.FromImage(image)

       Catch e As Exception
           ' The image is in indexed pixel format
           ' Create a temp bitmap

           bmpNew = New Bitmap(image.Width, image.Height)
           imageNew = bmpNew

           objGraphics = Graphics.FromImage(imageNew)

           ' Draw the contents of old bitmap to new bitmap
           objGraphics.DrawImage(image, New Rectangle(0, 0, _
                                 imageNew.Width, imageNew.Height), _
                                 0, 0, image.Width, image.Height, _
                                 GraphicsUnit.Pixel)

           image = imageNew
       End Try
       'Dim pThumbnail As System.Drawing.Image = New Bitmap(ms)
       image.GetThumbnailImage(10, 10, Nothing, _
       New IntPtr)
       Dim ms As MemoryStream = New MemoryStream
       image.Save(ms, Imaging.ImageFormat.Jpeg)
       image.Dispose()
       Dim bytImage(ms.Length) As Byte
       bytImage = ms.ToArray()
       ms.Close()
       ms = New MemoryStream(bytImage)
       Response.Clear() ' I found this call to Clear method to be
important.
       Response.Flush()
       Dim chunkSize As Integer = 1024
       Dim i As Integer
       For i = 0 To bytImage.Length Step chunkSize
           'check to see if the browser is still connected
           If (Not Response.IsClientConnected) Then
               Exit For
           End If
           Dim size As Integer = chunkSize
           If (i + chunkSize >= bytImage.Length) Then
               size = (bytImage.Length - i)
           End If
           Dim chunk(size - 1) As Byte
           ms.Read(chunk, 0, size)
           Response.BinaryWrite(chunk)
           Response.Flush()
       Next
       ms.Close()
       image.Dispose()
       lobjProduct = Nothing



Sincerely,
Vivek Mukherjee





From: Stoyan Damov <[EMAIL PROTECTED]>
Reply-To: "Unmoderated discussion of advanced .NET topics."

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to