OutOfMemoryException loading big image to Bitmap object with the Compact Framework

前端 未结 2 1803
无人及你
无人及你 2020-12-18 09:14

I have a problem with a memory leak.

I have this code in a button_click :

Private Sub Button3_Click(ByVal sender As System.Object, ByVal         


        
2条回答
  •  猫巷女王i
    2020-12-18 09:59

    Your leaking Gdi handles, wrap the stream and bitmap in Using clauses.

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    
        using ms As New IO.MemoryStream
            using bm As New Bitmap("\Application Data\imgs\IMG22.jpg")
                bm.Save(ms, Drawing.Imaging.ImageFormat.Jpeg)
            end using
        end using
    
    End Sub
    

提交回复
热议问题