2009-06-26 12 views
0

這是我從This Link調整上傳時我的圖片無法正常工作 - 我的緩衝區是什麼?

得到的代碼我希望用戶上傳一張照片,然後調整其大小.............

Public Sub ResizeFromStream(ByVal ImageSavePath As String, ByVal MaxSideSize As Integer, ByVal Buffer As System.IO.Stream) 

    Dim intNewWidth As Integer 
    Dim intNewHeight As Integer 
    Dim imgInput As System.Drawing.Image = System.Drawing.Image.FromStream(Buffer) 


    'Determine image format 
    Dim fmtImageFormat As ImageFormat = imgInput.RawFormat 

    'get image original width and height 
    Dim intOldWidth As Integer = imgInput.Width 
    Dim intOldHeight As Integer = imgInput.Height 

    'determine if landscape or portrait 
    Dim intMaxSide As Integer 

    If (intOldWidth >= intOldHeight) Then 
     intMaxSide = intOldWidth 
    Else 
     intMaxSide = intOldHeight 
    End If 

    If (intMaxSide > MaxSideSize) Then 
     'set new width and height 
     Dim dblCoef As Double = MaxSideSize/CDbl(intMaxSide) 

     intNewWidth = Convert.ToInt32(dblCoef * intOldWidth) 
     intNewHeight = Convert.ToInt32(dblCoef * intOldHeight) 

    Else 

     intNewWidth = intOldWidth 
     intNewHeight = intOldHeight 
    End If 
    'create new bitmap 
    Dim bmpResized As Drawing.Bitmap = New Drawing.Bitmap(imgInput, intNewWidth, intNewHeight) 

    'save bitmap to disk 
    bmpResized.Save(ImageSavePath, fmtImageFormat) 

    'release used resources 
    imgInput.Dispose() 
    bmpResized.Dispose() 
    Buffer.Close() 

End Sub 

現在,當我點擊在我的提交按鈕中,它必須執行我的代碼,但我不確定緩衝區字段的輸入必須是什麼?

Protected Sub btnUpload_Click() Handles btnUpload.Click 

    ResizeFromStream("~Pics", 200, ??????????) 

End Sub 

在此先感謝!

編輯 我需要從文件上傳控件中獲取我的圖像!

+0

那麼你想要圖像數據來自哪裏? – 2009-06-26 11:44:41

+0

從我的文件上傳控件調用FileUpload1 – Etienne 2009-06-26 12:14:34

回答

0

你可以傳遞一個流對象是這樣的:

Dim fs As New FileStream("C:\file.jpg", FileMode.Open) 

ResizeFromStream("~Pics", 200, fs) 

因此,代碼將是對文件「file.jpg」執行IO。這是一個非常粗略的例子,但是Jon Skeet問道,圖像來自哪裏的位置很重要。我的例子很簡單,就是「入門」類型。

+0

但我想從我的FileUpload控件調用FileUpload1 – Etienne 2009-06-26 12:13:48

0

FileUpload.FileContent獲取文件內容的流。

相關問題