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).
codice:<%@ 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 ") strFilename=server.mappath(right(request.QueryString("img"),len(request.QueryString("img"))-len(Request.ServerVariables("SERVER_NAME"))-7)) else 'Response.Write("case2 ") 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() %>

Rispondi quotando