在Richtextbox中保存图像时内存不足

时间:2018-11-21 01:57:11

标签: vb.net image out-of-memory richtextbox

我正在使用一个富文本框作为注释字段,使用户可以添加图像

现在当保存包含分辨率为4800x2800的图像的字段时,出现内存不足错误

我调试rtfText = Me.txtNotes.Rtf时发生错误

“ mscorlib.dll中发生了'System.OutOfMemoryException'类型的未处理异常”

大小有限制吗?我打算将图片限制为1920x1080,但不确定如何做,因为它在我无法执行任何操作之前会返回OOM错误(我认为它来自richtextbox.rtf)

如果能获得帮助限制可以添加的图像分辨率的请求,将不胜感激

Private Function ValidateRichTextImage() As Boolean
    Dim rtfText As String
    Dim width As Integer
    Dim height As Integer


    rtfText = Me.txtNotes.Rtf

    Dim widthRegex As New Regex("picwgoal[\d]+")
    Dim heightRegex As New Regex("pichgoal[\d]+")
    Dim widthmatch = widthRegex.Match(rtfText)
    If widthmatch.success Then
        Dim swidth As String = widthmatch.ToString.Replace("picwgoal", "")
        width = Integer.Parse(swidth) / 15
    End If

    Dim heightmatch = heightRegex.Match(rtfText)
    If heightmatch.success Then
        Dim sheight As String = heightmatch.ToString.Replace("pichgoal", "")
        height = Integer.Parse(sheight) / 15
    End If

    If rtfText.Contains("picwgoal") AndAlso width = 0 AndAlso height = 0 Then
        Me.Errors.Add("P1MMO0001", , Tb.Errors.ErrorTypeType.ErrorTypeError, , )
        Return False
    End If

    If width >= height Then 'landscape
        If width > mcImageWidth OrElse height > mcImageHeight Then
            Me.Errors.Add("P1MMO0001", , Tb.Errors.ErrorTypeType.ErrorTypeError, , )
            Return False
        End If
    Else 'portrait
        If width > mcImageHeight OrElse height > mcImageWidth Then
            Me.Errors.Add("P1MMO0001", , Tb.Errors.ErrorTypeType.ErrorTypeError, , )
            Return False
        End If
    End If

    Return True
End Function

0 个答案:

没有答案