Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
HTML Question.
Message
From
12/08/2003 19:49:22
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00819419
Message ID:
00819653
Views:
16
Joe,

There might be a way to resize the image using java. Alternatively, you can set the ImageUrl to a web page instead of a filename and use the System.Drawing.Image class to resize it.

I use the following code in a blank web page to retrieve an image from a table, but you could make some small modifications and use it to retrieve an image from a file:
Imports System.IO
Imports System.Drawing

Public Class ImageEmitter
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'QueryStrings:  ID  -  Primary Key value
        '               Key -  Primary Key column name
        '               Source - Table or View that contains the image
        '               Field - Column that contains the image
        '               Type - MIME type of the image (gif, jpeg, bmp, tiff
        '               Height - (optional) Height to scale the image
        '               Width - (optional) Width to scale the image

        Dim ID As String = Request.QueryString("ID")
        Dim Key As String = Request.QueryString("Key")
        Dim Source As String = Request.QueryString("Source")
        Dim Field As String = Request.QueryString("Field")
        Dim ImageHeight As Integer = CInt(Request.QueryString("Height"))
        Dim ImageWidth As Integer = CInt(Request.QueryString("Width"))

        Dim dr As SqlDataReader = SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings(Server.MachineName), CommandType.Text, _
            "SELECT " & Field & " FROM " & Source & " WHERE " & Key & "=" & ID)

        If Not dr Is Nothing Then

            dr.Read()
            Dim FullSizeData() As Byte = dr.GetValue(0)
            dr.Close()

            Dim FullSizeImage As System.Drawing.Image
            FullSizeImage = Image.FromStream(New MemoryStream(FullSizeData))

            ' Determine the image format and MIME content-type
            Dim SourceImageBitmap As New Bitmap(FullSizeImage)
            Dim SourceImageFormat As Imaging.ImageFormat = SourceImageBitmap.RawFormat

            SourceImageFormat = Imaging.ImageFormat.Jpeg

            If SourceImageFormat.Equals(Imaging.ImageFormat.Bmp) Then
                Response.ContentType = "image/x-ms-bmp"
            ElseIf SourceImageFormat.Equals(Imaging.ImageFormat.Gif) Then
                Response.ContentType = "image/gif"
            ElseIf SourceImageFormat.Equals(Imaging.ImageFormat.Jpeg) Then
                Response.ContentType = "image/jpeg"
            ElseIf SourceImageFormat.Equals(Imaging.ImageFormat.Png) Then
                Response.ContentType = "image/x-png"
            ElseIf SourceImageFormat.Equals(Imaging.ImageFormat.Tiff) Then
                Response.ContentType = "image/tiff"
            End If

            ' Scale the image if requested
            If ImageHeight > 0 And ImageWidth > 0 And (FullSizeImage.Height > ImageHeight Or FullSizeImage.Width > ImageWidth) Then
                Dim dummyCallBack As Image.GetThumbnailImageAbort
                dummyCallBack = New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)

                Dim ThumbNailImage As Image
                ThumbNailImage = FullSizeImage.GetThumbnailImage(ImageWidth, ImageHeight, dummyCallBack, IntPtr.Zero)
                ThumbNailImage.Save(Response.OutputStream, SourceImageFormat)
            Else
                FullSizeImage.Save(Response.OutputStream, SourceImageFormat)
            End If

        End If

    End Sub

    Function ThumbnailCallback() As Boolean
        Return False
    End Function

End Class
As a side benefit, GetThumbnailImage does a much better job scaling down an image than Internet Explorer. I.e. the scaled image looks a lot better.


>Chatter cant recieve points :( Actual HTML code looks like the following. Which DOES NOT work in a table... :+
>
>Thank you.
>
><IMG HEIGHT="80%" src="../images/01cPreparation.jpg" border="0" alt="01cPreparation">
>
>>Hi Joe,
>>
>>I haven't tried it, but, try to set the image's style (width and height to "100%") to see if that does it?
>>
>>Mike
>>
>>>I have pages created by my application that have an image that needs to dynamically size based on the browser window size to always show the entire image. Any ideas?
>>>
>>>My thanks in advance,
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform