这只是来自用户的报道。该程序的这一部分已在野外进行了相当广泛的测试和使用,并且在一段时间内没有改变。它似乎对她有用,而且最近才开始失败。由于图像来自资源,因此不需要处置。在我的测试中(并通过检查代码),这应该总是在UI线程上发生,所以我最好的猜测是程序已经以某种方式被破坏,导致资源中的图像实际上是无效的。这是否有意义,或者是否有更合理的解释。这是调用堆栈:
Msg: Parameter is not valid.
Source: System.Drawing
Assembly: System.Drawing, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a
Stack: at System.Drawing.Image.get_Width()
at System.Drawing.Image.get_Size()
at System.Windows.Forms.PictureBox.GetPreferredSizeCore(Size
proposedSize)
at System.Windows.Forms.Control.GetPreferredSize(Size proposedSize)
at
System.Windows.Forms.Layout.TableLayout.GetElementSize(IArrangedElement
element, Size proposedConstraints)
at System.Windows.Forms.Layout.TableLayout.InflateColumns(ContainerInfo
containerInfo, Size proposedConstraints, Boolean measureOnly)
at System.Windows.Forms.Layout.TableLayout.ApplyStyles(ContainerInfo
containerInfo, Size proposedConstraints, Boolean measureOnly)
at System.Windows.Forms.Layout.TableLayout.LayoutCore(IArrangedElement
container, LayoutEventArgs args)
at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container,
LayoutEventArgs layoutEventArgs)
at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs
levent)
at System.Windows.Forms.TableLayoutPanel.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement
affectedElement, String affectedProperty)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at
System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement
affectedElement, String affectedProperty)
at System.Windows.Forms.PictureBox.InstallNewImage(Image value,
ImageInstallationType installationType)
at System.Windows.Forms.PictureBox.set_Image(Image value)
at SayMore.Transcription.UI.OralAnnotationRecorderBaseDlg.UpdateDisplay()
at
SayMore.Transcription.UI.OralAnnotationRecorderBaseDlg.BeginRecording(TimeRange
timeRangeOfSourceBeingAnnotated)
at
SayMore.Transcription.UI.OralAnnotationRecorderBaseDlg.HandleRecordAnnotationMouseDown(Object
sender, MouseEventArgs e)
at
SayMore.Transcription.UI.OralAnnotationRecorderBaseDlg.OnLowLevelKeyDown(Keys
key)
at
SayMore.UI.LowLevelControls.MonitorKeyPressDlg.PreFilterMessage(Message& m)
at System.Windows.Forms.Application.ThreadContext.ProcessFilters(MSG&
msg, Boolean& modified)
at
System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
at
System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at SayMore.Model.Files.ComponentFile.RecordAnnotations(Form frm,
AudioRecordingType annotationType)
at
SayMore.Transcription.UI.TextAnnotationEditor.<>c_DisplayClassb.<HandleRecordedAnnotationButtonClick>b_a()
at
SayMore.Transcription.UI.TextAnnotationEditor.ShowSegmentationDialog(Action
showDialog)
at
SayMore.Transcription.UI.TextAnnotationEditor.HandleRecordedAnnotationButtonClick(Object
sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
以下是我们的代码中设置Image的方法:
protected override void UpdateDisplay()
{
_recDeviceIndicator.UpdateDisplay();
_labelListenButton.Image = (_waveControl.IsPlaying && _playingBackUsingHoldDownButton ?
Resources.ListenToOriginalRecordingDown : Resources.ListenToOriginalRecording);
_labelRecordButton.Image = (ViewModel.GetIsRecording() ?
Resources.RecordingOralAnnotationInProgress : Resources.RecordOralAnnotation);
_labelListenButton.Enabled = !ViewModel.GetIsRecording() &&
(ViewModel.CurrentUnannotatedSegment != null || !ViewModel.GetIsFullyAnnotated());
_labelRecordButton.Enabled = (ViewModel.GetSelectedSegmentIsLongEnough() &&
_userHasListenedToSelectedSegment &&
AudioUtils.GetCanRecordAudio(true) &&
!_waveControl.IsPlaying && !ViewModel.GetIsAnnotationPlaying());
_labelListenHint.Visible = _spaceBarMode == SpaceBarMode.Listen && _labelListenButton.Enabled;
_labelRecordHint.Visible = _spaceBarMode == SpaceBarMode.Record && _labelRecordButton.Enabled && !_reRecording && _recordingErrorMessage == null;
if (_spaceBarMode == SpaceBarMode.Done && _recordingErrorMessage == null)
{
if (!_labelFinishedHint.Visible)
{
_pictureIcon.Image = Resources.Green_check;
_labelFinishedHint.Visible = true;
_tableLayoutButtons.Controls.Add(_labelFinishedHint, 1, 0);
_tableLayoutButtons.SetRowSpan(_labelFinishedHint, 3);
AcceptButton = _buttonOK;
}
}
else
{
UdateErrorMessageDisplay();
if (_labelErrorInfo.Visible)
{
_pictureIcon.Image = Resources.Information_red;
if (_labelFinishedHint.Visible)
{
_labelFinishedHint.Visible = false;
_tableLayoutButtons.Controls.Remove(_labelFinishedHint);
}
_labelRecordHint.Visible = false;
}
else
{
_pictureIcon.Image = Resources.Information_blue;
}
float percentage = (_labelErrorInfo.Visible) ? 50 : 100;
_tableLayoutButtons.RowStyles[0].Height = (_labelErrorInfo.Visible) ? percentage : 0;
_tableLayoutButtons.RowStyles[1].Height = (_labelListenHint.Visible) ? percentage : 0;
_tableLayoutButtons.RowStyles[2].Height = (_labelRecordHint.Visible) ? percentage : 0;
}
base.UpdateDisplay();
}
我不确定设置Image的哪个调用导致异常,但根据上下文,我怀疑_labelRecordButton.Image设置为Resources.RecordingOralAnnotationInProgress的位置。关键在于,在每种情况下,Image都来自Resources,所以它应该始终有效。
答案 0 :(得分:0)
可能是什么。已知Bitmap类可以为任何类型的错误生成任何类型的异常,因此无法从异常类型派生问题的原因。我猜这将是一个内存不足的情况。