-
In rete ho trovato degli script asp.net (che io richiamo da pagine asp) che mi fanno il crop e il resize dell'immagine...l'unico problema è che tagliano l'immagine in un quadrato mentre io avrei bisogno di un'immagine rettangolare.
Ho cercato in giro ma non ho trovato niente.
-
-
Ti ringrazio...io programmo in asp ma prima o poi dovrò cominciare a imparare asp.net.
<%@ Page Language="VB"%> <%@ import Namespace="System.Drawing"%> <%@ import Namespace="System.Drawing.Imaging"%> <%@ import Namespace="System.Text.RegularExpressions"%> <% dim strFilename as string dim i as System.Drawing.Image dim b as System.Drawing.bitmap dim g as graphics If Left(request.QueryString("img"),4) = "http" then 'Response.Write("case1<br/>") strFilename=server.mappath(right(request.QueryString("img"),len(request.QueryString("img"))-len(Request.ServerVariables("SERVER_NAME"))-7)) else 'Response.Write("case2<br/>") strFilename = server.mappath(request.QueryString("img")) end if i = System.Drawing.Image.FromFile(strFilename) b = New system.drawing.bitmap(request.QueryString("opx"), request.QueryString("opx"), pixelformat.format24bpprgb) g = graphics.fromimage(b) g.InterpolationMode = 2 g.SmoothingMode = 4 g.PixelOffsetMode = 4 g.CompositingQuality = 4 ? scale and translate the image Dim NewLar, NewAlt, SrcX, SrcY If i.height>i.width then NewLar = i.width NewAlt = i.width SrcX=0 SrcY = (((i.height*request.QueryString("opx"))/i.width)-request.QueryString("opx"))/2 else NewLar = i.height NewAlt = i.height SrcY = 0 SrcX = (((i.width*request.QueryString("opx"))/i.height)-request.QueryString("opx"))/2 end if g.drawimage(i,New rectangle(0,0,request.QueryString("opx"),request.QueryString("opx")), New rectangle(SrcX,SrcY,NewLar,NewAlt), GraphicsUnit.Pixel) 'Response.Write(NewLar & " " & NewAlt & " " & SrcX & " " & SrcY) response.contenttype="image/jpeg" b.save(response.outputstream, imageformat.jpeg) b.dispose() %>lo richiamo da una pagina asp così: square.aspx?img=immagine.jpg&opx=150
dove 150 è l'altezza e la lunghezza dell'immagine.
-
-
-
Ho cambiato i parametri permettendoti di impostare larghezza e altezza.
Prova un po così ma l'immagine si potrebbe stirare:Dim strFilename As String dim i as System.Drawing.Image dim b as System.Drawing.bitmap dim g as graphics If Left(request.QueryString("img"),4) = "http" then 'Response.Write("case1<br/>") strFilename=server.mappath(right(request.QueryString("img"),len(request.QueryString("img"))-len(Request.ServerVariables("SERVER_NAME"))-7)) else 'Response.Write("case2<br/>") strFilename = server.mappath(request.QueryString("img")) End If 'Dim h As Integer = Request.QueryString("opx") + 200 i = System.Drawing.Image.FromFile(strFilename) b = New System.Drawing.Bitmap(Request.QueryString("w"), Request.QueryString("h"), PixelFormat.Format24bppRgb) g = graphics.fromimage(b) g.InterpolationMode = 2 g.SmoothingMode = 4 g.PixelOffsetMode = 4 g.CompositingQuality = 4 ? scale and translate the image Dim NewLar, NewAlt, SrcX, SrcY If i.height>i.width then NewLar = i.width NewAlt = i.width SrcX=0 SrcY = (((i.Height * Request.QueryString("w")) / i.Width) - Request.QueryString("w")) / 2 else NewLar = i.height NewAlt = i.height SrcY = 0 SrcX = (((i.Width * Request.QueryString("h")) / i.Height) - Request.QueryString("h")) / 2 End If 'Response.Write(SrcY & " - " & SrcX) g.DrawImage(i, New Rectangle(0, 0, Request.QueryString("w"), Request.QueryString("h")), New Rectangle(SrcX, SrcY, NewLar, NewAlt), GraphicsUnit.Pixel) 'Response.Write(NewLar & " " & NewAlt & " " & SrcX & " " & SrcY) Response.ContentType = "image/jpeg" b.Save(Response.OutputStream, ImageFormat.Jpeg) b.dispose()L'immagine va richiamata con questi parametri:
/img.aspx?img=img.gif&w=600&h=300
Dove w è la larghezza e h l'altezza -
-
-
-
Stavo abozzando qualcosa ma ho bisogno di un valido aiuto.
in questo modo l'immagine non è più quadrata ma rettangolare (800x300), riesco ad adattare anche l'immagine (per ora sto facendo prove con immagini di altezza superiore alla larghezza(primo if))...ma se cambio immagine non mi trovo più (è anche ovvio poichè sto usando numeri fissi anzicchè variabili (ad es.: NewLar = opxLARGHEZZA/1.52 invece che NewLar = opxLARGHEZZA/Qualche Formula).
<%@ Page Language="VB"%> <%@ import Namespace="System.Drawing"%> <%@ import Namespace="System.Drawing.Imaging"%> <%@ import Namespace="System.Text.RegularExpressions"%> <% dim strFilename as string dim opxLARGHEZZA as string dim opxALTEZZA as string dim i as System.Drawing.Image dim b as System.Drawing.bitmap dim g as graphics If Left(request.QueryString("img"),4) = "http" then 'Response.Write("case1<br/>") strFilename=server.mappath(right(request.QueryString("img"),len(request.QueryString("img"))-len(Request.ServerVariables("SERVER_NAME"))-7)) else 'Response.Write("case2<br/>") strFilename = server.mappath(request.QueryString("img")) end if i = System.Drawing.Image.FromFile(strFilename) opxLARGHEZZA="800" opxALTEZZA="300" b = New system.drawing.bitmap(opxLARGHEZZA, opxALTEZZA, pixelformat.format24bpprgb) g = graphics.fromimage(b) g.InterpolationMode = 2 g.SmoothingMode = 4 g.PixelOffsetMode = 4 g.CompositingQuality = 4 ? scale and translate the image Dim NewLar, NewAlt, SrcX, SrcY If i.height>i.width then NewLar = opxLARGHEZZA/1.52 NewAlt = opxALTEZZA/1.52 SrcX=0 SrcY = (((i.height*opxALTEZZA)/i.width)-opxALTEZZA)/2 else NewLar = i.height NewAlt = i.height SrcY = 0 SrcX = (((i.width*request.QueryString("opx"))/i.height)-request.QueryString("opx"))/2 end if g.drawimage(i,New rectangle(0,0,opxLARGHEZZA,opxALTEZZA), New rectangle(SrcX,SrcY,NewLar,NewAlt), GraphicsUnit.Pixel) 'Response.Write(NewLar & " " & NewAlt & " " & SrcX & " " & SrcY) Response.ContentType = "image/jpeg" b.Save(Response.OutputStream, ImageFormat.Jpeg) b.Dispose() %>
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi