DebbieDRR
asked on
Poor Quality On Uploaded Images
I am trying to resize a posted file and then upload it to my server. I can resize it and upload it, but once its there the quality is very poor. Can someone tell me what I need to add or change in my code so the image quality is high.
Thanks
<%@ Page Language="vb" aspcompat=true debug=true%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing. Imaging" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
Response.Expires = 60
dim imgHeight, imgWidth, h, w, xInt, yInt, optRatio, imgRatio, optWidth, optHeight, cngWidth, cngHeight
dim conn, rs, cmd, prm, c, ft, errFile, i, m, x, photosArray(4,7), ErrorMsg, imgURL, perChange
Dim thumbNailImg as System.Drawing.Image
Dim fullSizeImg as System.Drawing.Image
optWidth = 115
optHeight = 100
optRatio = optWidth\optHeight
Try
imgURL = myPath + myFileName
dim g as System.Drawing.Image = System.Drawing.Image.FromS tream(flPo sOne.Poste dFile.Inpu tStream)
dim thisFormat = g.rawformat
if thisformat.equals(system.d rawing.ima ging.image format.Gif ) then
response.contenttype="imag e/gif"
else
response.contenttype="imag e/jpeg"
end if
imgHeight = g.Height
imgWidth = g.Width
imgRatio = imgWidth/imgHeight
if imgRatio > 1 then
cngWidth = optWidth
perChange = optWidth/imgWidth
cngHeight = imgHeight * perChange
Else
cngHeight = optHeight
perChange = optHeight/imgHeight
cngWidth = imgWidth * perChange
End If
dim imgOutput as New Bitmap(g, cngWidth, cngHeight)
imgOutput.save(imgURL, thisformat)
g.dispose()
imgOutput.dispose()
catch Exp as exception
Response.Write(exp)
End Try
End Sub
</script>
Thanks
<%@ Page Language="vb" aspcompat=true debug=true%>
<%@ Import Namespace="System.Drawing"
<%@ Import Namespace="System.Drawing.
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
Response.Expires = 60
dim imgHeight, imgWidth, h, w, xInt, yInt, optRatio, imgRatio, optWidth, optHeight, cngWidth, cngHeight
dim conn, rs, cmd, prm, c, ft, errFile, i, m, x, photosArray(4,7), ErrorMsg, imgURL, perChange
Dim thumbNailImg as System.Drawing.Image
Dim fullSizeImg as System.Drawing.Image
optWidth = 115
optHeight = 100
optRatio = optWidth\optHeight
Try
imgURL = myPath + myFileName
dim g as System.Drawing.Image = System.Drawing.Image.FromS
dim thisFormat = g.rawformat
if thisformat.equals(system.d
response.contenttype="imag
else
response.contenttype="imag
end if
imgHeight = g.Height
imgWidth = g.Width
imgRatio = imgWidth/imgHeight
if imgRatio > 1 then
cngWidth = optWidth
perChange = optWidth/imgWidth
cngHeight = imgHeight * perChange
Else
cngHeight = optHeight
perChange = optHeight/imgHeight
cngWidth = imgWidth * perChange
End If
dim imgOutput as New Bitmap(g, cngWidth, cngHeight)
imgOutput.save(imgURL, thisformat)
g.dispose()
imgOutput.dispose()
catch Exp as exception
Response.Write(exp)
End Try
End Sub
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sub Page_Load(sender as Object, e as EventArgs)
Response.Expires = 60
dim imgHeight, imgWidth, h, w, xInt, yInt, optRatio, imgRatio, optWidth, optHeight, cngWidth, cngHeight
dim conn, rs, cmd, prm, c, ft, errFile, i, m, x, photosArray(4,7), ErrorMsg, imgURL, perChange
Dim thumbNailImg as System.Drawing.Image
Dim fullSizeImg as System.Drawing.Image
optWidth = 115
optHeight = 100
optRatio = optWidth\optHeight
Try
imgURL = myPath + myFileName
dim g as System.Drawing.Image = System.Drawing.Image.FromS
dim thisFormat = g.rawformat
if thisformat.equals(system.d
response.contenttype="imag
else
response.contenttype="imag
end if
imgHeight = g.Height
imgWidth = g.Width
imgRatio = imgWidth/imgHeight
if imgRatio > 1 then
cngWidth = optWidth
perChange = optWidth/imgWidth
cngHeight = imgHeight * perChange
Else
cngHeight = optHeight
perChange = optHeight/imgHeight
cngWidth = imgWidth * perChange
End If
dim imgOutput as New Bitmap(g, cngWidth, cngHeight)
'Microsoft code for setting JPEG quality level
Dim eps As EncoderParameters = New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Q
Dim ici As ImageCodecInfo = GetEncoderInfo("image/jpeg
Dim dummyCallBack As System.Drawing.Image.GetTh
dummyCallBack = New System.Drawing.Image.GetTh
imgOutput.save(imgURL, ".jpg",ici,eps)
g.dispose()
imgOutput.dispose()
catch Exp as exception
Response.Write(exp)
End Try
End Sub
'More Microsoft code for setting JPEG quality level
Private Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
Dim j As Integer
Dim encoders As ImageCodecInfo()
encoders = ImageCodecInfo.GetImageEnc
For j = 0 To encoders.Length
If encoders(j).MimeType = mimeType Then
Return encoders(j)
End If
Next j
Return Nothing
End Function
Function ThumbnailCallback() As Boolean
Return False
End Function