vb.net - 在 Richtextbox 中保存图像时 OutOfMemory
问题描述
我正在使用 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
解决方案
推荐阅读
- javascript - 在 Angular 中使用 `fetch`
- reactjs - 来自 github 的 react-native 链接库
- r - 堆积区域图表每个元素在前一个之上
- symfony - Symfony 缓冲区内容到树枝模板
- python - 如何更改我的相机在opencv中读取的图像大小?机器学习模型显示错误
- sonos - 验证访问令牌的最佳方法?
- c++ - 子类按钮不会在每次重复点击时产生动画
- javascript - 为什么 insertRowsAfter() 在我的电子表格中不起作用?
- python - scikit-learn 随机森林永远不会完成训练,冻结
- php - 使 URL 查询对 php 可读