如何在SSRS中旋转图像

时间:2014-06-15 17:00:51

标签: css vb.net reporting-services

我正在使用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。

1 个答案:

答案 0 :(得分:2)

Bitmap类有几个内置的旋转和翻转机制:

Dim bmp As Bitmap = <bitmap from somewhere>

bmp.RotateFlip(RotateFlipType.Rotate270FlipNone)

这将图像旋转270度CW,与90 CCW相同。存在许多其他轮换选项,例如:

Rotate270FlipXY
Rotate270FlipY
Rotate270FlipX

以及基于Rotate90...Rotate180...

的变体

我还应该指出,您可以将它们组合起来,而不是嵌套Using语句:

Using font As New Font(New FontFamily(fontName), 36),
       tmpBitmap As New Bitmap(1, 1, Imaging.PixelFormat.Format32bppArgb)
       Br As New Brush(.....),
       otherBMP As New Bitmap(....)

       <your code here>

                       <rather than here>

这减少了许多人发现令人讨厌的代码上的缩进量。您还可以通过在顶部添加System.Drawing.Font语句(C#中的Imports)来缩短其中一些引用,例如using

Imports System.Drawing

(显然,您目前无法使用Imports将SSRS作为评论中的链接,因此请忽略该部分。