Я использую метод webservice для вызова в бизнес-логике (один класс написан на vb). Я получаю inputppath и путь туда, где мне нужно сохранить изображение в этом методе. Мне нужно создать эскиз, а также я должен сохранить исходное изображение. Я хочу сохранить masterimage в одной папке и ее thumnail в другой папке. Я использовал следующий кодКак сохранить изображение в папку
Public Function CreateThumbNails(ByVal intWidth As Integer, ByVal strInputFilePath As String, ByVal strFileName As String, ByVal strOutputFilePath As String) As String
Dim lnWidth As Integer = intWidth
Dim lnHeight As Integer = 100
Dim bmpOut As System.Drawing.Bitmap = Nothing
Try
Dim loBMP As New Bitmap(strInputFilePath)
Dim lnRatio As Decimal
Dim lnNewWidth As Integer = 0
Dim lnNewHeight As Integer = 0
If loBMP.Width < lnWidth AndAlso loBMP.Height < lnHeight Then
lnNewWidth = loBMP.Width
lnNewHeight = loBMP.Height
End If
If loBMP.Width > loBMP.Height Then
lnRatio = CDec(lnWidth)/loBMP.Width
lnNewWidth = lnWidth
Dim lnTemp As Decimal = loBMP.Height * lnRatio
lnNewHeight = CInt(lnTemp)
Else
lnRatio = CDec(lnHeight)/loBMP.Height
lnNewHeight = lnHeight
Dim lnTemp As Decimal = loBMP.Width * lnRatio
lnNewWidth = CInt(lnTemp)
End If
' *** This code creates cleaner (though bigger) thumbnails and properly
' *** and handles GIF files better by generating a white background for
' *** transparent images (as opposed to black)
bmpOut = New Bitmap(lnNewWidth, lnNewHeight)
Dim g As Graphics = Graphics.FromImage(bmpOut)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight)
g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight)
loBMP.Dispose()
bmpOut.Save(HttpContext.Current.Server.MapPath(strOutputFilePath) + strFileName)
bmpOut.Dispose()
Return strOutputFilePath + strFileName
Catch e As Exception
Throw New Exception("ThumbNail Creation Failed")
Return ""
End Try
End Function
Какой код я должен включить, чтобы сохранить изображение в исходном размере в другой папке. Может кто-нибудь помочь?
Является ли метод под названием CreateThumbnails действительно подходящим местом для создания копии основного изображения? Возможно, вы захотите сделать это где-то еще (или изменить имя метода) –