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(img Height as integer, imgWidth as integer, imgFileName as
String, imgQuality as integer)
Dim myNewImage As System.drawing. Image
Dim myImageCodecInf o As ImageCodecInfo
Dim myEncoder As Encoder
Dim myEncoderParame ter As EncoderParamete r
Dim myEncoderParame ters As EncoderParamete rs
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.Outpu tStream,
System.Drawing. Imaging.ImageFo rmat.Jpeg)
Case Else
If imgWidth = 0 Then imgWidth = 90
If imgHeight = 0 Then imgHeight = 90
myNewImage = mgGetThumbNail( imgFileName, imgWidth,
imgHeight)
'Image Type
'myImageCodecIn fo = GetEncoderInfo( "image/tiff")
myImageCodecInf o = GetEncoderInfo( "image/jpeg")
'Image Qualiy for Jpeg only
myEncoder = Encoder.Quality
myEncoderParame ters = New EncoderParamete rs(1)
'25L is the quality level Hard to 25 coded for now
'but I would use imgQuality to create the 25L for
example
myEncoderParame ter = New EncoderParamete r(myEncoder,
25L)
myEncoderParame ters.Param(0) = myEncoderParame ter
'myNewImage.Sav e(Response.Outp utStream,
ImageFormat.Jpe g)
myNewImage.Save (Response.Outpu tStream, myImageCodecInf o,
myEncoderParame ters)
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. GetImageEncoder s()
For J = 0 To encoders.Length
If encoders(J).Mim eType = 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.GetThu mbnailImage(int Width, intHeight, Nothing,
Nothing)
myBitmap.Dispos e()
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.W idth, myBitmap.Height )
End If
Dim myImg As Bitmap = New Bitmap(myBitmap , mysize)
Return myImg
myBitmap.Dispos e()
End Function
"Chris D" <qw*****@hotmai l.com> wrote in message
news:3f******** @news.nucleus.c om...
Hi,
I have an application where a user uploads an image and I create two
thumbnails. One a small image and the second is a larger image but still
smaller then the original. I store these in SQL 2000 server.
The quality of the small thumbnail is ok, but the quality of the larger
image is terrible. I tried both Jpeg and Gif formats and there is no
difference.
Is there any way to control the compression level of a Jpeg??
If any one can give me some suggestions I would greatly appreciate it.
Chris