Image.Save()对从位图派生的图像抛出GDI +异常

时间:2019-02-21 15:02:05

标签: vb.net image visual-studio bitmap gdi+

我有两个类:ChartObject和GrowthChartPane。

ChartObject具有GetChart()方法,该方法将位图转换为返回的Drawing.Image。

<div class="app">
  <ul class="row">
    <li class="node male">Ken Cross</li>
    <li class="node female">Karen Heffron</li>
  </ul>
  <ul class="row">
    <li class="node female">Melissa Cross</li>
    <li class="node female">Kristen Cross</li>
    <li class="node male">Jacob Cross</li>
  </ul>
</div>

GrowthChartPane在加载时,将调用ChartObject.GetChart()以实例化Drawing.Image对象。尝试保存从增长图返回的图像时,会发生异常。该方法相当大,但这是异常的最后一小段。

    Public Function GetChart() As Drawing.Image
    Dim chartImage As Drawing.Image
    Dim gr As Graphics
    Dim brush As Brush = Brushes.Blue
    If m_bIsBoy Then
        brush = Brushes.Red
    End If

    Using fs As New FileStream(m_sChartImageFileName, FileMode.Open, FileAccess.Read)
        chartImage = Bitmap.FromStream(fs)
        gr = Graphics.FromImage(chartImage)
    End Using

    For Each Point As PointObject In m_lstUpperPoints
        If Not Point.IsVisible Then Continue For
        Dim x As Integer = m_objUpperHorizontalAxis.ValueToPoint(Point.HorizontalValue)
        Dim y As Integer = m_objUpperVerticalAxis.ValueToPoint(Point.VerticalValue)
        gr.FillEllipse(brush, New RectangleF(x - 4, y - 4, 8, 8))
    Next
    For Each Point As PointObject In m_lstLowerPoints
        If Not Point.IsVisible Then Continue For
        Dim x As Integer = m_objLowerHorizontalAxis.ValueToPoint(Point.HorizontalValue)
        Dim y As Integer = m_objLowerVerticalAxis.ValueToPoint(Point.VerticalValue)
        gr.FillEllipse(brush, New RectangleF(x - 4, y - 4, 8, 8))
    Next
    DrawHeaderAndTable(gr)

    Return chartImage
End Function

我已经确认该文件不存在,但是Image.Save()仍然抛出异常

我已经对此主题进行了一些研究,并且有很多不同的解决方案,但是这使我担心流是开放的。 我已经读过需要打开流以保存图像,并且可以将流直接传递到Save()方法,但是我很好奇这两个类之间的交互如何进行。

0 个答案:

没有答案