我正在使用 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 的菜鸟。
最佳答案
Bitmap
类有几个内置的旋转和翻转机制:
Dim bmp As Bitmap = <bitmap from somewhere>
bmp.RotateFlip(RotateFlipType.Rotate270FlipNone)
这会将图像顺时针旋转 270 度,与逆时针旋转 90 度相同。存在许多其他旋转选项,例如:
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>
这减少了很多人觉得烦人的代码缩进量。您还可以通过在顶部添加 Imports
语句(在 C# 中使用 using
)来缩短其中一些引用,例如 System.Drawing.Font
:
Imports System.Drawing
(显然您目前不能将 Imports
与 SSRS 一起用作评论中的链接,因此请忽略该部分)。
关于css - 如何在 SSRS 中旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24231982/