我正在使用webservice来调用businesslogics中的方法(一个用vb编写的类)。我正在获取inputppath和路径,我必须在那个方法中保存图像。我必须创建缩略图,我还要保存原始图像.Means我想将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
我必须包含哪些代码才能将原始大小的图像保存在另一个文件夹中。任何人都可以帮忙吗?
答案 0 :(得分:1)
编辑触发开心。你不需要从位图中保存它。该文件已存在。只需复制文件。
如果我理解了您的问题,那么您希望在将图像操作到服务器上的新位置之前保存图像。
该文件已作为服务器上的文件存在。该文件的文件位置作为参数(strInputFilePath)传递给您的函数。
最简单的方法是使用File.Copy()将文件复制到所需的位置。