Here are some routines I just put together. Anything with "img..." is a
image parameter that you need to pass in. I am confused on your height to
width scaling but I think you have the right idea. Play around with that a
bit more but for now leave it out and try these routunies. I would not use
GetThumbnail for images bigger than 100x100.
Sub StreamImage(imgHeight as integer, imgWidth as integer, imgFileName as
String, imgQuality as integer)
Dim myNewImage As System.drawing.Image
Dim myImageCodecInfo As ImageCodecInfo
Dim myEncoder As Encoder
Dim myEncoderParameter As EncoderParameter
Dim myEncoderParameters As EncoderParameters
Try
Select Case imgQuality
Case Is = 0
If imgWidth = 0 Then imgWidth = 200
If imgHeight = 0 Then imgHeight = 200
myNewImage = mgAdjustBitmap(imgFileName, imgWidth,
imgHeight)
myNewImage.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
Case Else
If imgWidth = 0 Then imgWidth = 90
If imgHeight = 0 Then imgHeight = 90
myNewImage = mgGetThumbNail(imgFileName, imgWidth,
imgHeight)
'Image Type
'myImageCodecInfo = GetEncoderInfo("image/tiff")
myImageCodecInfo = GetEncoderInfo("image/jpeg")
'Image Qualiy for Jpeg only
myEncoder = Encoder.Quality
myEncoderParameters = New EncoderParameters(1)
'25L is the quality level Hard to 25 coded for now
'but I would use imgQuality to create the 25L for
example
myEncoderParameter = New EncoderParameter(myEncoder,
25L)
myEncoderParameters.Param(0) = myEncoderParameter
'myNewImage.Save(Response.OutputStream,
ImageFormat.Jpeg)
myNewImage.Save(Response.OutputStream, myImageCodecInfo,
myEncoderParameters)
End Select
Catch
End Try
End Sub
Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
Dim J As Integer
Dim encoders As ImageCodecInfo()
encoders = ImageCodecInfo.GetImageEncoders()
For J = 0 To encoders.Length
If encoders(J).MimeType = mimeType Then
GetEncoderInfo = encoders(J)
Exit For
End If
Next
End Function
Function mgGetThumbNail(ByVal strFile As String, ByVal intWidth As
Integer, ByVal intHeight As Integer) As System.drawing.Image
Dim myBitmap As Bitmap = New Bitmap(strFile)
Return myBitmap.GetThumbnailImage(intWidth, intHeight, Nothing,
Nothing)
myBitmap.Dispose()
End Function
Function mgAdjustBitmap(ByVal strFile As String, ByVal intHorz As
Integer, ByVal intVert As Integer) As Bitmap
Dim mysize As Size
Dim myBitmap As Bitmap = New Bitmap(strFile)
If intHorz > 0 Then
mysize = New Size(intHorz, intVert)
Else
mysize = New Size(myBitmap.Width, myBitmap.Height)
End If
Dim myImg As Bitmap = New Bitmap(myBitmap, mysize)
Return myImg
myBitmap.Dispose()
End Function