Originariamente inviato da Sonikag
C# Grazie
allora, la pagina di esempio che ho è in basic, ma utilizzo la libreria c#
pagina prova
codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="fit_img.aspx.vb" Inherits="CorsoApogeo_GDI_adatta_immagine_al_contenitore_fit_img" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Pagina senza titolo</title>
<script language="javascript" type="text/javascript">
// <!CDATA[
function Button1_onclick(p)
{
var w = document.getElementById("larghezza_rettangolo").value;
var h = document.getElementById("altezza_rettangolo").value;
var src = "fit_img.aspx?img=" + p + "&w=" + w + "&h=" + h;
document.getElementById("img1").src = src;
}
// ]]>
</script>
<link href="../../../stili/Styles.css" rel="stylesheet" type="text/css" />
</head>
<body style="background-color:silver">
<h3>Adatta immagine al contenitore</h3>
<form id="form1" runat="server">
<table>
<tr>
<td>larghezza contenitore:</td>
<td>
<input id="larghezza_rettangolo" type="text" value="300" style="border:1px black solid; width:50px" />
</td>
</tr>
<tr>
<td>altezza contenitore:</td>
<td>
<input id="altezza_rettangolo" type="text" value="250" style="border:1px black solid; width:50px" />
</td>
</tr>
<tr>
<td>
<input id="Button1" type="button" value="Fit image (centrata)" onclick="return Button1_onclick('1')" />
</td>
<td>
<input id="Button2" type="button" value="Fit image (centrata)" onclick="return Button1_onclick('2')" />
</td>
</tr>
</table>
<hr />
<div>
[img]fit_img.aspx?img=1&w=300&h=250[/img]
</div>
</form>
</body>
</html>
codice
codice:
Option Strict On
Partial Class CorsoApogeo_GDI_adatta_immagine_al_contenitore_fit_img
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'recupero il parametro query string p_img inviato
'se = a "1" o "2" restituisco immagine
Dim p_img As String = libreria.RequestParams("img")
If p_img = "1" Or p_img = "2" Then
GetImg(p_img)
End If
End Sub
Private Sub GetImg(ByVal p As String)
'immagine da visualizzare
Dim immagineInput As String = "C:\dati\Prove Nicon\prova.jpg"
'dimensioni in px del contenitore
Dim w As Integer = CInt(RequestParams("w"))
Dim h As Integer = CInt(RequestParams("h"))
'leggo l'immagine
Dim bmp As Bitmap = img.ImgLoad(immagineInput)
'la ridimensiono per adattarla al contenitore
If p = "1" Then
'default: è centrata con colore sottofondo bianco
img.ImgFit(bmp, w, h)
Else
'non la voglio centrata
img.ImgFit(bmp, w, h, Color.White, False)
End If
'la salvo nello stream di ritorno: viene fatto il dispose
'naturalmente vengono usati i valori predefiniti
img.ImgSaveToResponseOutputStream(bmp)
End Sub
End Class
La classe nel prossimo post.