2014-06-15 17 views
1

旋轉圖像,我使用,我的使用下面的代碼轉換成條碼圖像,該代碼是從here採取SQL建設SSRS的報告。我不是VB.Net開發者,但是這段代碼對我來說非常合適。 問題是我的報告佈局是垂直條形碼圖像而不是水平的,而且我沒有看到任何可以旋轉圖像OOB的選項。任何人都可以幫助我在這裏使用下面的代碼旋轉圖像。如何在SSRS

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

你可能只需要'bmp.RotateFlip(RotateFlipType.Rotate270FlipNone)'或類似取決於哪個方向翻轉。 – Plutonix

+0

@Plutonix - [似乎爲我工作(http://i.stack.imgur.com/rAtUp.png) –

+1

更改示例項目是在加入'newBitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone)'在'newBitmap.Save(ms,System.Drawing.Imaging.ImageFormat.Png)'之前,並在報告中將ImageProperties設置爲「原始大小」而非「剪輯」。 –

回答

2

Bitmap類具有多個內置的旋轉和翻轉機制:

Dim bmp As Bitmap = <bitmap from somewhere> 

bmp.RotateFlip(RotateFlipType.Rotate270FlipNone) 

此旋轉圖像270度CW,相同90 CCW。許多其他旋轉選項存在,如:

Rotate270FlipXY 
Rotate270FlipY 
Rotate270FlipX 

以及其變體基於Rotate90...Rotate180...


我也應該指出的是,而不是嵌套使用語句,你可以將它們組合起來:

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> 

這減少強加給許多發現annnoying代碼的縮進量。您還可以縮短一些人引用,如System.Drawing.Font的在頂部(在C#using)添加Imports聲明:

Imports System.Drawing 

(顯然目前不能使用Imports與SSRS作爲評論的鏈接,所以忽略那部分)。

+1

[貌似'imports'不能在此上下文中使用(http://social.msdn.microsoft.com/Forums/sqlserver/en-US/960d0956-804d-4cf2-9c2a-e6e654d21964/ssrs - 和 - 進口) –