【发布时间】:2014-06-15 17:00:51
【问题描述】:
我正在使用 SQL 在 SSRS 中构建报告,其中我使用下面的代码将条形码转换为图像,此代码取自 here。我不是VB.Net 开发人员,但这段代码非常适合我。
问题是我的报告的布局是垂直条形码图像而不是水平的,我看不到任何可以旋转图像 OOB 的选项。任何人都可以在这里帮助我使用以下代码旋转图像。
Public Shared Function GenerateImage(ByVal fontName As String, ByVal stringText As String) As Byte()
Dim oGraphics As System.Drawing.Graphics
Dim barcodeSize As System.Drawing.SizeF
Dim ms As System.IO.MemoryStream
Dim i As System.Drawing.Image
Using font As New System.Drawing.Font(New System.Drawing.FontFamily(fontName), 36)
Using tmpBitmap As New System.Drawing.Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
oGraphics = System.Drawing.Graphics.FromImage(tmpBitmap)
oGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel
barcodeSize = oGraphics.MeasureString(stringText, font)
oGraphics.Dispose()
End Using
Using newBitmap As New System.Drawing.Bitmap(barcodeSize.Width, barcodeSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
oGraphics = System.Drawing.Graphics.FromImage(newBitmap)
oGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel
Using oSolidBrushWhite As New System.Drawing.SolidBrush(System.Drawing.Color.White)
Using oSolidBrushBlack As New System.Drawing.SolidBrush(System.Drawing.Color.Black)
oGraphics.FillRectangle(oSolidBrushWhite, New System.Drawing.Rectangle(0, 0, barcodeSize.Width, barcodeSize.Height))
oGraphics.DrawString(stringText, font, oSolidBrushBlack, 0, 0)
End Using
End Using
ms = New System.IO.MemoryStream()
newBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
End Using
End Using
Return ms.ToArray()
End Function
我绝对是 VB.Net 中的 NOOB。
【问题讨论】:
-
你可能只需要
bmp.RotateFlip(RotateFlipType.Rotate270FlipNone)或类似的,这取决于它被翻转的方向。 -
@Plutonix - Appears to work for me
-
对示例项目的更改是在
newBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)之前添加newBitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone)并将报告中的 ImageProperties 设置为“原始大小”而不是“剪辑”顺便说一句。 -
添加了一些其他观察/提示作为答案
-
@hkhan 根据我之前的评论使用完全限定名称引用它。您也许可以添加
imports System.Drawing,但我看到您的示例代码的其余部分没有这样做,所以这在 RS 嵌入式代码中可能是不可能的。
标签: css vb.net reporting-services