<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Asp.Net] Crop e resize rettangolare]]></title><description><![CDATA[<p dir="auto">In rete ho trovato degli script <a href="http://asp.net" rel="nofollow ugc">asp.net</a> (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.</p>
<p dir="auto">Ho cercato in giro ma non ho trovato niente.</p>
]]></description><link>https://dev.connect.gt/topic/114172/asp-net-crop-e-resize-rettangolare</link><generator>RSS for Node</generator><lastBuildDate>Mon, 30 Nov 2026 14:42:22 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/114172.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Nov 2009 12:03:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Asp.Net] Crop e resize rettangolare on Mon, 09 Nov 2009 13:10:58 GMT]]></title><description><![CDATA[<p dir="auto">Stavo abozzando qualcosa ma ho bisogno di un valido aiuto.</p>
<p dir="auto">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).</p>
<pre><code>&lt;%@ Page Language="VB"%&gt;
&lt;%@ import Namespace="System.Drawing"%&gt;
&lt;%@ import Namespace="System.Drawing.Imaging"%&gt;
&lt;%@ import Namespace="System.Text.RegularExpressions"%&gt;

&lt;%
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&lt;br/&gt;")
    strFilename=server.mappath(right(request.QueryString("img"),len(request.QueryString("img"))-len(Request.ServerVariables("SERVER_NAME"))-7))
else
    'Response.Write("case2&lt;br/&gt;")
    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&gt;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 &amp; " " &amp; NewAlt &amp; " " &amp; SrcX &amp; " " &amp; SrcY)

Response.ContentType = "image/jpeg"
b.Save(Response.OutputStream, ImageFormat.Jpeg)
b.Dispose()
%&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/post/869729</link><guid isPermaLink="true">https://dev.connect.gt/post/869729</guid><dc:creator><![CDATA[luca1317]]></dc:creator><pubDate>Mon, 09 Nov 2009 13:10:58 GMT</pubDate></item><item><title><![CDATA[Reply to [Asp.Net] Crop e resize rettangolare on Fri, 06 Nov 2009 15:28:34 GMT]]></title><description><![CDATA[<p dir="auto">No problem, so benissimo che il tempo è sacro. Appena puoi mi trovi quì.</p>
]]></description><link>https://dev.connect.gt/post/869733</link><guid isPermaLink="true">https://dev.connect.gt/post/869733</guid><dc:creator><![CDATA[luca1317]]></dc:creator><pubDate>Fri, 06 Nov 2009 15:28:34 GMT</pubDate></item><item><title><![CDATA[Reply to [Asp.Net] Crop e resize rettangolare on Fri, 06 Nov 2009 14:43:20 GMT]]></title><description><![CDATA[<p dir="auto">Ho capito cosa vuoi fare ma mi servirebbe più tempo per ragionarci sopra. C'è bisogno di qualche calcolo ulteriore.</p>
<p dir="auto">Se riesco ti faccio sapere. Non ho molto tempo purtroppo</p>
]]></description><link>https://dev.connect.gt/post/869728</link><guid isPermaLink="true">https://dev.connect.gt/post/869728</guid><dc:creator><![CDATA[fusionman]]></dc:creator><pubDate>Fri, 06 Nov 2009 14:43:20 GMT</pubDate></item><item><title><![CDATA[Reply to [Asp.Net] Crop e resize rettangolare on Fri, 06 Nov 2009 13:43:23 GMT]]></title><description><![CDATA[<p dir="auto">Ho provato ma purtroppo l'immagine stira...non viene fatto il ritaglio o crop.</p>
<p dir="auto">In pratica è come se mettessi l'immagine in html senza usare asp o <a href="http://asp.net" rel="nofollow ugc">asp.net</a> modificando l'altezza e la larghezza.</p>
]]></description><link>https://dev.connect.gt/post/869734</link><guid isPermaLink="true">https://dev.connect.gt/post/869734</guid><dc:creator><![CDATA[luca1317]]></dc:creator><pubDate>Fri, 06 Nov 2009 13:43:23 GMT</pubDate></item><item><title><![CDATA[Reply to [Asp.Net] Crop e resize rettangolare on Fri, 06 Nov 2009 13:17:47 GMT]]></title><description><![CDATA[<p dir="auto">Ho cambiato i parametri permettendoti di impostare larghezza e altezza.<br />
Prova un po così ma l'immagine si potrebbe stirare:</p>
<pre><code>    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&lt;br/&gt;")
    strFilename=server.mappath(right(request.QueryString("img"),len(request.QueryString("img"))-len(Request.ServerVariables("SERVER_NAME"))-7))
else
    'Response.Write("case2&lt;br/&gt;")
    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&gt;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 &amp; " - " &amp; 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 &amp; " " &amp; NewAlt &amp; " " &amp; SrcX &amp; " " &amp; SrcY)
    Response.ContentType = "image/jpeg"
    b.Save(Response.OutputStream, ImageFormat.Jpeg)
b.dispose()
</code></pre>
<p dir="auto">L'immagine va richiamata con questi parametri:<br />
/img.aspx?img=img.gif&amp;w=600&amp;h=300<br />
Dove w è la larghezza e h l'altezza</p>
]]></description><link>https://dev.connect.gt/post/869727</link><guid isPermaLink="true">https://dev.connect.gt/post/869727</guid><dc:creator><![CDATA[fusionman]]></dc:creator><pubDate>Fri, 06 Nov 2009 13:17:47 GMT</pubDate></item><item><title><![CDATA[Reply to [Asp.Net] Crop e resize rettangolare on Fri, 06 Nov 2009 11:18:42 GMT]]></title><description><![CDATA[<p dir="auto">Lo script sopra crea un immagine quadrata della dimensione che tu vuoi da qualsiasi immagine, rettangolare o no...effettua il ridimensionamento e taglia il supefluo.</p>
<p dir="auto">Vorrei invece che creasse un'immagine rettangolare, secondo te è fattibile?</p>
]]></description><link>https://dev.connect.gt/post/869732</link><guid isPermaLink="true">https://dev.connect.gt/post/869732</guid><dc:creator><![CDATA[luca1317]]></dc:creator><pubDate>Fri, 06 Nov 2009 11:18:42 GMT</pubDate></item><item><title><![CDATA[Reply to [Asp.Net] Crop e resize rettangolare on Fri, 06 Nov 2009 11:10:49 GMT]]></title><description><![CDATA[<p dir="auto">Scusa ma se ho capito bene ti scala l'immagine in proporzione.<br />
Cioè se tu gli dai un'immagine rettangolare dovrebbe rimanere tale ma rimpicciolita o sbaglio?</p>
]]></description><link>https://dev.connect.gt/post/869726</link><guid isPermaLink="true">https://dev.connect.gt/post/869726</guid><dc:creator><![CDATA[fusionman]]></dc:creator><pubDate>Fri, 06 Nov 2009 11:10:49 GMT</pubDate></item><item><title><![CDATA[Reply to [Asp.Net] Crop e resize rettangolare on Fri, 06 Nov 2009 10:26:51 GMT]]></title><description><![CDATA[<p dir="auto">Ti ringrazio...io programmo in asp ma prima o poi dovrò cominciare a imparare <a href="http://asp.net" rel="nofollow ugc">asp.net</a>.</p>
<pre><code>&lt;%@ Page Language="VB"%&gt;
&lt;%@ import Namespace="System.Drawing"%&gt;
&lt;%@ import Namespace="System.Drawing.Imaging"%&gt;
&lt;%@ import Namespace="System.Text.RegularExpressions"%&gt;

&lt;%
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&lt;br/&gt;")
    strFilename=server.mappath(right(request.QueryString("img"),len(request.QueryString("img"))-len(Request.ServerVariables("SERVER_NAME"))-7))
else
    'Response.Write("case2&lt;br/&gt;")
    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&gt;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 &amp; " " &amp; NewAlt &amp; " " &amp; SrcX &amp; " " &amp; SrcY)
response.contenttype="image/jpeg"
b.save(response.outputstream, imageformat.jpeg)
b.dispose() 
%&gt;
</code></pre>
<p dir="auto">lo richiamo da una pagina asp così: square.aspx?<strong>img</strong>=immagine.jpg&amp;<strong>opx</strong>=150</p>
<p dir="auto">dove 150 è l'altezza e la lunghezza dell'immagine.</p>
]]></description><link>https://dev.connect.gt/post/869731</link><guid isPermaLink="true">https://dev.connect.gt/post/869731</guid><dc:creator><![CDATA[luca1317]]></dc:creator><pubDate>Fri, 06 Nov 2009 10:26:51 GMT</pubDate></item><item><title><![CDATA[Reply to [Asp.Net] Crop e resize rettangolare on Fri, 06 Nov 2009 10:15:30 GMT]]></title><description><![CDATA[<p dir="auto">Non si può sempre trovare la cosa specifica che ci serve. Spesso bisogna adattare quello che c'è.<br />
Quello che hai trovato è gia un'ottima base di partenza.</p>
<p dir="auto">Se non è troppo codice prova a postarlo (l'aspx). Vediamo se è fattibile velocemente.</p>
]]></description><link>https://dev.connect.gt/post/869725</link><guid isPermaLink="true">https://dev.connect.gt/post/869725</guid><dc:creator><![CDATA[fusionman]]></dc:creator><pubDate>Fri, 06 Nov 2009 10:15:30 GMT</pubDate></item></channel></rss>