Jag höll på med den här igår :)
du får ändra 100 till 300 antar jag..
du får skriva om den så att den passar exakt det du ska ha den till, men nånting borde du kunna få ut av den..
som den är nu så skalar den om bilder som är större än 100px på någon ledd.
är bilden 4:3 så blir den 100*x och om den är 3:4 så blir den x*100
dim fullSizeImg As System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromFile(imageFullPathFile)
'Skapa tumnaglar
Dim TIA As System.Drawing.Image.GetThumbnailImageAbort
Dim newImg As New Bitmap(fullSizeImg)
Dim NewHeight As Integer = 0
Dim NewWidth As Integer = 0
Dim NewRatio As Decimal = 0
fullSizeImg.Dispose()
fullSizeImg = newImg
'undersök om bilden behöver skalas ned
If fullSizeImg.Height > 100 OR fullSizeImg.Width > 100 Then
If fullSizeImg.Height < fullSizeImg.Width Then
'4:3 räkna ut höjd-bredd-förhållande
NewRatio = fullSizeImg.Width / fullSizeImg.Height
'räkna ut en ny höjd
NewHeight = Decimal.Round((100 / NewRatio), 0 ) 'runda av till heltal
fullSizeImg = fullSizeImg.GetThumbnailImage(100, NewHeight, TIA, IntPtr.Zero)
Else
'3:4 räkna ut höjd-bredd-förhållande
NewRatio = fullSizeImg.Height / fullSizeImg.Width
'räkna ut en ny bredd
NewWidth = Decimal.Round((100 / NewRatio), 0 ) 'runda av till heltal
fullSizeImg = fullSizeImg.GetThumbnailImage(NewWidth, 100, TIA, IntPtr.Zero)
End If
Else
fullSizeImg = fullSizeImg.GetThumbnailImage(fullSizeImg.Width, fullSizeImg.Height, TIA, IntPtr.Zero)
End If
Dim eps As EncoderParameters = New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 40)
Dim ici As ImageCodecInfo = GetEncoderInfo("image/jpeg")
dim newFullPath as string = Server.MapPath("databases/artikelbilder/") & "tumme_" & fn
fullSizeImg.Save(newFullPath, ici, eps)
fullSizeImg.Dispose()