ASP.NET bilmiyorsan ASP'de component kullanmadan yapman şöyle mümkün:
Bir adet aspx sayfan olmalı. Sadece resmin yeniden boyutlanmış halini çekmek için.
resizeImage.aspx
<%@ import namespace="System" %>
<%@ import namespace="System.Drawing" %>
<%@ import namespace="System.Drawing.Imaging" %>
<%@ import namespace="System.IO" %>
<script runat="server">
Function NewthumbSize(currentwidth, currentheight)
Dim w as string = Request("w")
Dim h as string = Request("h")
if w="0" or w="" Then w="200"
if h="0" or h="" Then h="131"
Dim NewSize as New Size(CInt(w), CInt(h))
Return NewSize
End Function
Sub sendFile()
Dim g as System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(Request("src")))
Dim thisFormat = g.rawformat
Dim thumbSize as New size
thumbSize = NewthumbSize(g.width,g.height)
Dim imgOutput as New Bitmap(g, thumbSize.width, thumbSize.height)
If thisFormat.equals(system.drawing.imaging.imageformat.Gif) Then
Response.ContentType = "image/gif"
ElseIf thisFormat.equals(system.drawing.imaging.imageformat.Bmp) Then
Response.ContentType = "image/bmp"
ElseIf thisFormat.equals(system.drawing.imaging.imageformat.Png) Then
Response.ContentType = "image/png"
ElseIf thisFormat.equals(system.drawing.imaging.imageformat.Tiff) Then
Response.ContentType = "image/tiff"
Else
Response.ContentType = "image/jpeg"
End If
imgOutput.Save(Response.OutputStream, thisformat) ' output to the user
g.Dispose()
imgOutput.Dispose()
End Sub
Sub sendError()
Dim imgOutput as New bitmap(120, 120, pixelformat.format24bpprgb)
Dim g as graphics = graphics.fromimage(imgOutput) ' create a New graphic object from the above bmp
g.clear(color.yellow)
g.drawString("ERROR!", New font("verdana",14,fontstyle.bold),systembrushes.windowtext, New pointF(2,2))
Response.ContentType = "image/gif"
imgOutput.save(Response.OutputStream, imageformat.gif) ' output to the user
g.Dispose()
imgOutput.Dispose()
End Sub
</script>
<%
Response.Clear
If Request("src") = "" Then
Call sendError()
Else
If file.exists(Server.MapPath(Request("src"))) Then
Call sendFile()
Else
Call sendError()
End if
End If
Response.End
%>
Sayfa içerisinde kullanmak için ise resmin src'si olarak aşağıdaki gibi adres vermelisin:
<img src="resizeImage.aspx?src=/images/resimadi.jpg&w=300&h=200%>" border="0" />
Not :
w = resmin genişliğinin pixel değeri
h = resmin yüksekliğinin pixel değeri
Not - 2 :
ASP Forever
|