【问题标题】:Different metafile rendering on Win8.1 and Win7Win8.1和Win7上不同的元文件渲染
【发布时间】:2015-03-09 17:08:11
【问题描述】:

Solution to reproduce

我正在使用以下代码来绘制图元文件: {

<DllImport("gdi32.dll", EntryPoint:="CopyEnhMetaFileA", BestFitMapping:=False, ThrowOnUnmappableChar:=True, _
   SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function CopyEnhMetaFile(ByVal hemfSrc As IntPtr, ByVal lpszFile As String) As IntPtr
End Function

<DllImport("gdi32.dll", EntryPoint:="DeleteEnhMetaFile", _
   SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function DeleteEnhMetaFile(ByVal hemfSrc As IntPtr) As Boolean
End Function

Private Sub DrawArialTest()
    Dim TestString = "11111111111112"
    Dim metafileStream = New MemoryStream()
    Dim offScreenDC = Graphics.FromHwndInternal(IntPtr.Zero)
    Dim myImagePointer = offScreenDC.GetHdc()
    Dim Image = New Metafile(metafileStream, myImagePointer, EmfType.EmfPlusDual)

    ' Create the graphics object
    Using g = Walker.GraphicsUtilities.GdiGraphics.FromImage(Image)
        SetGraphicsSettings(g)
        Try
            ' Draw in the metafile
            Dim sFormat = New StringFormat
            sFormat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces
            Dim Y = 0
            For intI As Single = 0 To 30
                Using font = New Font("Arial", 6 + intI, FontStyle.Regular)
                    Dim size = g.MeasureString(TestString, font, PointF.Empty, sFormat)
                    Dim rec = New RectangleF(0, Y, size.Width, size.Height)
                    g.DrawString(TestString, font, System.Drawing.Brushes.Black, rec, sFormat)
                    g.DrawRectangles(Pens.Red, New RectangleF() {rec})
                    Y += rec.Height
                End Using

            Next
            sFormat.Dispose()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Using
    SaveEnhMetafile(Image, "c:\temp\test.emf")
End Sub

Public Shared Function SaveEnhMetafile(ByVal sourceMetafile As Metafile, ByVal fileName As String) As Boolean
    Dim hEMF As IntPtr = DirectCast(sourceMetafile.Clone, Metafile).GetHenhmetafile()
    If Not hEMF.Equals(New IntPtr(0)) Then
        If System.IO.File.Exists(fileName) Then Kill(fileName)
        DeleteEnhMetaFile(CopyEnhMetaFile(hEMF, fileName))
        DeleteEnhMetaFile(hEMF)
        Return True
    End If
    Return False
End Function
Sub SetGraphicsSettings(ByVal g As IGraphics)
    g.SmoothingMode = SmoothingMode.AntiAlias
    g.InterpolationMode = InterpolationMode.HighQualityBicubic
    g.CompositingQuality = CompositingQuality.GammaCorrected
    'g.TextRenderingHint = Text.TextRenderingHint.ClearTypeGridFit
    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
    g.PixelOffsetMode = PixelOffsetMode.HighQuality
End Sub

}

如果我随后打开此测试中的元文件,我会看到以下内容:

Win8.1 64位

Win7 64位

我无法使用除 Arial 之外的任何其他字体重现此错误。任何帮助将不胜感激。

谢谢!

Link to metafile

【问题讨论】:

    标签: fonts windows-8.1 gdi+ gdi system.drawing


    【解决方案1】:

    如果其他人对此感兴趣,这是我从微软那里得到的:

    Microsoft 于 2015 年 5 月 22 日下午 1:39 发布 你好!感谢您的反馈意见。这是 GDIPlus API GdipMeasureString 中的错误,而不是 Graphics.MeasureString 中的错误。很抱歉你被误导到这个论坛。我为 GDI+ 团队打开了一个内部错误,他们将对其进行调查和分类。由于此错误在 Dot Net Framework 之外,因此我正在解决它。 谢谢, Windows 窗体团队

    【讨论】:

      猜你喜欢
      • 2017-05-31
      • 1970-01-01
      • 2021-12-19
      • 2014-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多