gpt4 book ai didi

C#/VB.NET : Howto improve anti-alias quality

转载 作者:太空宇宙 更新时间:2023-11-03 11:33:19 25 4
gpt4 key购买 nike

问题:
在 Reporting Service 中,我需要一个垂直的、从底部开始、从下到上、水平居中对齐的文本。

唯一的方法是在代码中创建一个图像,并将该图像设置到标题列中。

请看下面的代码。

基本上,它工作正常,只是抗锯齿质量很糟糕。
我可以做些什么来改进它吗?
请看下面的截图:

SSRS Problem

垂直文本有点苍白,而不是全黑,
并且文本周围也有涂抹,背景颜色。以及它看起来比左边的文本更粗,但两者都有 arial 格式,大小 8,粗体

我已经尝试了
的所有其他值System.Drawing.Text.TextRenderingHint.*, 以及根本没有抗锯齿

但目前的似乎是最不蹩脚的。我也尝试过更改图像格式,但无济于事:

Function LoadImage2(ByVal sImageText As String, ByVal sImageTextMax As String) As System.Drawing.Image
sImageTextMax = sImageTextMax.PadRight(15)
Dim iFontSize As Integer = 8 '//Change this as needed
Dim bmpImage As New System.Drawing.Bitmap(1, 1)
Dim iWidth As Integer = 0
Dim iHeight As Integer = 0
Dim bgColor As System.Drawing.Color = System.Drawing.Color.LemonChiffon ' LightGray
Dim TextColor As System.Drawing.Color = System.Drawing.Color.Black

Dim fsFontStyle As System.Drawing.FontStyle = System.Drawing.FontStyle.Bold

'// Create the Font object for the image text drawing.
Dim MyFont As New System.Drawing.Font("Arial", iFontSize, fsFontStyle, System.Drawing.GraphicsUnit.Point)
'// Create a graphics object to measure the text's width and height.
'Graphics(MyGraphics = Graphics.FromImage(bmpImage))
Dim MyGraphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmpImage)
'// This is where the bitmap size is determined.
iWidth = MyGraphics.MeasureString(sImageTextMax, MyFont).Width
iHeight = MyGraphics.MeasureString(sImageTextMax, MyFont).Height
'// Create the bmpImage again with the correct size for the text and font.
'bmpImage = New Drawing.Bitmap(bmpImage, New Drawing.Size(iWidth, iHeight))

'inches = pixels / dpi
'pixel = inches * dpi
'1 centimeter = 0.393700787 inch
'pixel = cm * 0.393700787 * dpi


' vice-versa, because 270° turn
iHeight = 1 * 0.393700787 * bmpImage.HorizontalResolution 'x DPI
iWidth = 2.25 * 0.393700787 * bmpImage.VerticalResolution 'y DPI


bmpImage = New System.Drawing.Bitmap(bmpImage, New System.Drawing.Size(iHeight, iWidth))

'// Add the colors to the new bitmap.
MyGraphics = System.Drawing.Graphics.FromImage(bmpImage)
MyGraphics.Clear(bgColor)
MyGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias

MyGraphics.TranslateTransform(0, iWidth)
MyGraphics.RotateTransform(270)

Dim iTextStartX As Single = 2
Dim iTextStartY As Single = CSng(iHeight) / CSng(2.0) - CSng(iFontSize) / CSng(2.0)
iTextStartY -= 2

MyGraphics.DrawString(sImageText, MyFont, New System.Drawing.SolidBrush(TextColor), iTextStartX, iTextStartY)
MyGraphics.Flush()
Return bmpImage
End Function


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.PictureBox1.Image = LoadImage2("test", "")
End Sub



' This piece is only needed in reporting service itselfs
Function LoadImage(ByVal strText As String) As Byte()
Dim ThisImageFormat As System.Drawing.Imaging.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg


Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream
Dim bitmapBytes As Byte()
Dim bmpImage As System.Drawing.Image = LoadImage2(strText, "")


bmpImage.Save(stream, ThisImageFormat)
bitmapBytes = stream.ToArray
stream.Close()
bmpImage.Dispose()
Return bitmapBytes
End Function

最佳答案

我遇到了这个问题,但仅限于某些浏览器。我认为这是一个浏览器问题(IE)。 Firefox 和 Chrome 似乎没问题。

最后我决定在 html 中手动构建我的报告并使用 HighCharts对于图形。然后我使用 wkHTMLtoPDF 将其全部渲染为 PDF

它结合得很好,抗锯齿问题已经消失。我认为您可能会在 SQL Reporting Services 中遇到这些问题。

关于C#/VB.NET : Howto improve anti-alias quality,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7080723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com