2009-08-12 24 views
0

私はビジネスロジックのメソッドを呼び出すためにwebserviceを使用しています(1つのクラスはVBで書かれています)。私はそのメソッドのイメージを保存する必要があるinputppathとパスを取得しています。私は元の画像を保存する必要があります。私は1つのフォルダとthumnailの異なるフォルダにmasterimageを保存したい。次のコードを使用しましたイメージをフォルダに保存する方法

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

CreateThumbnailsというメソッドは、実際にマスターイメージのコピーを作成する正しい場所ですか? –

答えて

1

EDITトリガーハッピー。それをビットマップから保存する必要はありません。ファイルは既にそこにあります。ファイルをコピーするだけです。

私はあなたの質問を理解している場合は、サーバー上の新しい場所に操作する前に、イメージを保存する必要があります。

このファイルは、すでにサーバー上のファイルとして存在しています。そのファイルのファイルの場所は、関数(strInputFilePath)としてパラメーターに渡されます。

File.Copy()を使用してファイルを目的の場所にコピーするのが最も簡単です。

+0

元の画像を保存してから処分した後にコードを書く必要があります – user42348

+0

GDI +で一般的なエラーが発生しました。このエラーは、loBMP.Save(strMyOtherPath)行に表示されています。理由は何でしょうか? – user42348

関連する問題