0
我使用https://code.google.com/p/slimdx/issues/detail?id=707上的代碼將System.Drawing.Bitmap轉換爲SlimDX.Direct2D.Bitmap。我已經使用了ËX一個ç牛逼大號Ÿ相同的代碼之前,如果完美。現在,當我畫圖像SlimDX GDI位圖到Direct2D位圖是比例〜1.5 - 2 X
Dim TheBitmap As SlimDX.Direct2D.Bitmap = LoadBitmap(New Bitmap(New MemoryStream(TheBytesThatIGotOffTheNetworkStream)))
SlimDX.Direct2D.WindowRenderTarget.DrawBitmap(TheBitmap)
我得到一個位圖已經縮放1.5至2倍。如果我保存System.Drawing.Bitmap,它是完美的。我以前做過這個,它從來沒有縮放過。我甚至試圖擺脫流並從硬盤加載位圖。它沒有工作。謝謝。
我的代碼:
Form1.vb的:
Imports SlimDX
Imports System.Text
Imports System.Threading
Imports System.IO
Public Class Form1
Dim F As Direct2D.Factory
Dim WRTP As Direct2D.WindowRenderTargetProperties
Dim WRT As Direct2D.WindowRenderTarget
Dim TheBitmap As Direct2D.Bitmap
Function LoadBitmap(drawingBitmap As Bitmap) As Direct2D.Bitmap
Dim result As Direct2D.Bitmap = Nothing
Dim drawingBitmapData As BitmapData = drawingBitmap.LockBits(New Rectangle(0, 0, drawingBitmap.Width, drawingBitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb)
Dim dataStreamxx As DataStream = New DataStream(drawingBitmapData.Scan0, drawingBitmapData.Stride * drawingBitmapData.Height, True, False)
Dim properties As Direct2D.BitmapProperties = New Direct2D.BitmapProperties()
properties.PixelFormat = New Direct2D.PixelFormat(DXGI.Format.R8G8B8A8_UNorm, Direct2D.AlphaMode.Premultiplied)
result = New Direct2D.Bitmap(WRT, New Size(drawingBitmap.Width, drawingBitmap.Height), dataStreamxx, drawingBitmapData.Stride, properties)
drawingBitmap.UnlockBits(drawingBitmapData)
Return result
End Function
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
F = New Direct2D.Factory()
WRTP = New Direct2D.WindowRenderTargetProperties()
WRTP.Handle = Me.Handle
WRTP.PixelSize = Me.PixelSize
WRT = New Direct2D.WindowRenderTarget(F, WRTP)
End Sub
Public Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
WRT.BeginDraw()
WRT.Clear()
If Not IsNothing(TheBitmap) Then
WRT.DrawBitmap(TheBitmap)
End If
WRT.EndDraw()
End Sub
Sub Main()
Dim Command As TCP.Command
While True
If TCP.Listener.Pending() Then
TCP.Clients.Add(TCP.Listener.AcceptTcpClient())
TCP.Streams.Add(TCP.Clients.Last().GetStream())
End If
For a=0 To TCP.Clients.Count-1
If TCP.Streams(a).DataAvailable Then
Command=TCP.ReadCommand(TCP.Streams(a))
If Encoding.ASCII.GetString(Command.Command) = "Bitmap"
TheBitmap=LoadBitmap(New Bitmap(New MemoryStream(Command.SubCommands(0))) 'Convert it.
Me.Invalidate()
End If
End If
Next
End While
End Sub
End Class