Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
ASP.NET 2.0 / 3.5 / 4.0
Ridimensionare immagine
giovedì 12 giugno 2014 - 06.39
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
Elenco Tags
VB.NET
|
.NET 3.5
|
Windows Server 2008
|
Visual Studio 2008
basicdany
Profilo
| Expert
590
messaggi | Data Invio:
gio 12 giu 2014 - 06:39
ciao a tutti, ho sempre problema di ridimensionare img, ho trovato in rete questa procedura che sara utile a molti:
Public Function ImageResize(ByVal strImageSrcPath As String _
, ByVal strImageDesPath As String _
, Optional ByVal intWidth As Integer = 0 _
, Optional ByVal intHeight As Integer = 0) As String
If System.IO.File.Exists(strImageSrcPath) = False Then Exit Function
Dim objImage As System.Drawing.Image = System.Drawing.Image.FromFile(strImageSrcPath)
If intWidth > objImage.Width Then intWidth = objImage.Width
If intHeight > objImage.Height Then intHeight = objImage.Height
If intWidth = 0 And intHeight = 0 Then
intWidth = objImage.Width
intHeight = objImage.Height
ElseIf intHeight = 0 And intWidth <> 0 Then
intHeight = Fix(objImage.Height * intWidth / objImage.Width)
ElseIf intWidth = 0 And intHeight <> 0 Then
intWidth = Fix(objImage.Width * intHeight / objImage.Height)
End If
Dim imgOutput As New Bitmap(objImage, intWidth, intHeight)
Dim imgFormat = objImage.RawFormat
objImage.Dispose()
objImage = Nothing
If strImageSrcPath = strImageDesPath Then System.IO.File.Delete(strImageSrcPath)
' send the resized image to the viewer
imgOutput.Save(strImageDesPath, imgFormat)
imgOutput.Dispose()
Return strImageDesPath
End Function
il mio problema che l'immagine di partenza non e presa un percorso ma un controllo
FILEUPLOAD di asp,
e la destinazione e di tipo byte per essere scritta in database:
Dim imgByte As Byte() = Nothing
Dim File As HttpPostedFile = imgUpload.PostedFile
imgByte = New Byte(File.ContentLength - 1) {}
come posso modificare quella procedura postata sopra?
grazie a tutti.
ridaria
Profilo
| Expert
905
messaggi | Data Invio:
gio 12 giu 2014 - 10:40
o adegui l'una o l'altra.
suggerisco questa:
salvi l'immagine anche sul disco del server e non solo sul database, e quindi hai anche un percorso fisico per utilizzare la procedura di ridimensionamento.
Ciao
Riccardo D'Aria
basicdany
Profilo
| Expert
590
messaggi | Data Invio:
gio 12 giu 2014 - 10:54
Ciao, punterei su modificare la procedura, prendendo l immagine dal controllo upload , come? Puoi autarmi?
Grazie
ridaria
Profilo
| Expert
905
messaggi | Data Invio:
ven 13 giu 2014 - 07:07
nomeFile1 = FileUpload1.FileName
estensioneFile = IO.Path.GetExtension(nomeFile1)
nomeFile1 = "file_1" & estensioneFile
FileUpload1.SaveAs("percorsoOveSalvareilFile" & "nomeFile)
questo blocco di codice salva il file sul disco del server.
CIAo
fammi sapere
Riccardo D'Aria
basicdany
Profilo
| Expert
590
messaggi | Data Invio:
ven 13 giu 2014 - 08:12
Ciao,devo chiedere ad aruba il percorso del server pero!
Io optava per evitare questo di trovare una procedura che effettua resize con ingresso img da controllo fileupload, e come risultato in byte da scrivere su db sql server.
Puoi aiutarmi??
Grazie
ridaria
Profilo
| Expert
905
messaggi | Data Invio:
ven 13 giu 2014 - 10:55
>Ciao,devo chiedere ad aruba il percorso del server pero!
non devi chiedere il percorso.
c'è la classe HttpServerUtility che serve a cio e ad altro:
HttpServerUtility.MapPath ti restituisce la root del server.
CMQ studia questo:
http://msdn.microsoft.com/it-it/library/system.web.httpserverutility.mappath%28v=vs.110%29.aspx
Ciao
fammi sapere
Riccardo D'Aria
basicdany
Profilo
| Expert
590
messaggi | Data Invio:
ven 13 giu 2014 - 19:45
Ciao, dopo varie prove cercando di scrivere il file di immagine su spazio o trovato un altra procedura che esegure resize img:
Public Shared Function ResizeImage(ByVal image As Image, ByVal size As Size, Optional ByVal preserveAspectRatio As Boolean = True) As Image
Dim newWidth As Integer
Dim newHeight As Integer
If preserveAspectRatio Then
Dim originalWidth As Integer = image.Width
Dim originalHeight As Integer = image.Height
Dim percentWidth As Single = CSng(Size.Width) / CSng(originalWidth)
Dim percentHeight As Single = CSng(Size.Height) / CSng(originalHeight)
Dim percent As Single = If(percentHeight < percentWidth, percentHeight, percentWidth)
newWidth = CInt(originalWidth * percent)
newHeight = CInt(originalHeight * percent)
Else
newWidth = Size.Width
newHeight = Size.Height
End If
Dim newImage As Image = New Bitmap(newWidth, newHeight)
Using graphicsHandle As Graphics = Graphics.FromImage(newImage)
graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic
graphicsHandle.DrawImage(image, 0, 0, newWidth, newHeight)
End Using
Return newImage
End Function
QUALCUNO PUOI AIUTARMI A MODIFICARE LA FUNZIONE IN MODO DA AVERE CON
INGRESSO, IL FILE IMMAGINE CONTENUTO NELL'OGGETTO fileupoload di ASP
USCITA DELLA FUNZIONE IN BYTE PER POTERLO SCRIVERE IN CAMPO di tipo "image" in tabella slq server.
grazie a tutti
basicdany
Profilo
| Expert
590
messaggi | Data Invio:
lun 16 giu 2014 - 13:05
Ciao,mi ha contattato aruba dicendo che non e possibile scrivere file sullo spazio se non con un ftp !!!
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !