http://www.opencenter.ru/phototest/
Алгоритм создания один. Только вот слева картинка сохранена фотожопом через Save For Web, а справа через Save As. Оригиналы обеих картинок нормального качества. Только вот при создании thumbnails правая картинка "портится", а левая ведет себя нормально. Уже не первый день бьюсь над проблемой. Если кто знает, в чем может быть подвох, расскажите, плиз.
Может кто знает более эффективный способ создания thumbnails?
Заранее спасибо.
ЗЫ вот код, который я использую (ShowImageJPG.aspx):
- Код: Выделить всё
<%@Import Namespace="System" %>
<%@Import Namespace="System.Drawing" %>
<%@Import Namespace="System.Drawing.Imaging" %>
<script language="VB" runat="server">
Function ThumbnailCallback() As Boolean
Return False
End Function
Private Function GetEncoder(ByVal format As ImageFormat) As ImageCodecInfo
Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageDecoders()
Dim codec As ImageCodecInfo
For Each codec In codecs
If codec.FormatID = format.Guid Then
Return codec
End If
Next codec
Return Nothing
End Function
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Read in the image filename to create a thumbnail of
Dim imageUrl As String = Request.QueryString("img")
Dim imageFolder As String = Request.QueryString("folder")
'Read in the width and height
Dim imageHeight As Decimal = Request.QueryString("h")
Dim imageWidth As Decimal = Request.QueryString("w")
'Make sure that the image URL doesn't contain any /'s or \'s
If imageUrl.IndexOf("/") >= 0 Or imageUrl.IndexOf("\") >= 0 Then
'We found a / or \
Response.End()
End If
'Make sure that the image URL doesn't contain any /'s or \'s
If imageFolder.IndexOf("/") >= 0 Or imageFolder.IndexOf("\") >= 0 Then
'We found a / or \
Response.End()
End If
'Add on the appropriate directory
imageUrl = Request.ServerVariables("URI") & imageFolder & "/" & imageUrl
Dim fullSizeImg As System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
If imageWidth = 0 Then
If fullSizeImg.Width > fullSizeImg.Height Then imageWidth = 250 Else imageWidth = 200
End If
If imageWidth > 0 Then
Dim lngK As Decimal
lngK = fullSizeImg.Width / imageWidth
imageHeight = fullSizeImg.Height / lngK
End If
'Do we need to create a thumbnail?
Response.ContentType = "image/jpg"
If imageHeight > 0 And imageWidth > 0 Then
Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort
dummyCallBack = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
Dim thumbNailImg As System.Drawing.Image
thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, IntPtr.Zero)
Dim jgpEncoder As ImageCodecInfo = GetEncoder(ImageFormat.Jpeg)
Dim myEncoder As System.Drawing.Imaging.Encoder = System.Drawing.Imaging.Encoder.Quality
Dim myEncoderParameters As New EncoderParameters(1)
Dim myEncoderParameter As New EncoderParameter(myEncoder, 100&)
myEncoderParameters.Param(0) = myEncoderParameter
thumbNailImg.Save(Response.OutputStream, jgpEncoder, myEncoderParameters)
'thumbNailImg.Save(Response.OutputStream, ImageFormat.Jpeg)
'Clean up / Dispose...
thumbNailImg.Dispose()
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg)
End If
'Clean up / Dispose...
fullSizeImg.Dispose()
End Sub
</script>