showing a list of dynamically resized images...

M

Milsnips

hi there,

i've a function that reads image filenames from database, and displays into
a repeater control, but what i'm trying to acheive is as i loop through each
filename, i want to resize it to say 100 pixels wide(which i already have
function for) and it returns a System.Drawing.Bitmap object - now this, i
want to get the image from here and put it into an <asp:image> control.

my code so far...

---------------------------------------------------
Function ResizeImage(ByVal s As IO.Stream, ByVal maxWidth As Integer) As
System.Drawing.Bitmap
Dim oImage As System.Drawing.Image =
System.Drawing.Image.FromStream(s)

'check image width and orientation...
Dim newWidth, newHeight As Integer
If oImage.Width > maxWidth Then
Dim tmpW As Decimal = oImage.Width / maxWidth
newWidth = maxWidth
newHeight = oImage.Height / tmpW
Else
'image size is okay.. use the original uploaded size.
newWidth = oImage.Width
newHeight = oImage.Height
End If
Dim bmpOut As New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(bmpOut)
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.FillRectangle(Brushes.White, 0, 0, newWidth, newHeight)
g.DrawImage(oImage, 0, 0, newWidth, newHeight)
oImage.Dispose()

ResizeImage = bmpOut
g.Dispose()
g = Nothing
bmpOut.Dispose()
bmpOut = Nothing
oImage.Dispose()
oImage = Nothing
End Function

Private Sub photoslist_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
photoslist.ItemDataBound
If Not (e.Item.DataItem Is Nothing) Then
Dim p As PhotoAlbum.Photo = e.Item.DataItem
Dim img As WebControls.Image = e.Item.FindControl("img")

'resize the image on the fly....
'i know this is wrong, here is where i need help...
Dim s As New IO.StreamReader(Server.MapPath(".") & "\gallery\" &
Request.QueryString("id") & "\" & p.Filename)
img.imageurl = ResizeImage(s.BaseStream, 120)

End If
End Sub
---------------------------------------------------

how would i go about this?

thanks,
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top