2009-08-12 4 views
0

weblogic을 사용하여 businesslogics (vb로 작성된 하나의 클래스) 메소드를 호출합니다. inputPath 및 경로가 해당 메소드의 이미지를 저장해야하는 위치에 있습니다. 축소판을 작성해야하며 나는 원본 image.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

CreateThumbnails라는 메서드는 실제로 마스터 이미지의 복사본을 만드는 데 적합한 위치입니까? –

답변

1

편집 trigger happy. 비트 맵에서 저장하지 않아도됩니다. 파일이 이미 있습니다. 그냥 파일을 복사하십시오.

질문을 이해하면 서버의 새 위치로 조작하기 전에 이미지를 저장하고 싶습니다.

해당 파일은 이미 서버에 파일로 존재합니다. 해당 파일의 파일 위치는 매개 변수 (strInputFilePath)로 함수에 전달됩니다.

가장 간단한 방법은 File.Copy()을 사용하여 파일을 원하는 위치에 복사하는 것입니다.

+0

원래 이미지를 저장하지 않고 처분해야하는 코드 – user42348

+0

GDI +에서 일반 오류가 발생했습니다.이 오류는 loBMP.Save (strMyOtherPath) 행에 있습니다. 이유가 무엇일까요? – user42348

관련 문제