SlimDX GDI 位图到 Direct2D 位图的比例约为 1.5 - 2 X
Posted
技术标签:
【中文标题】SlimDX GDI 位图到 Direct2D 位图的比例约为 1.5 - 2 X【英文标题】:SlimDX GDI Bitmap to Direct2D Bitmap is scale ~ 1.5 - 2 X 【发布时间】:2013-11-22 00:46:07 【问题描述】:我正在使用https://code.google.com/p/slimdx/issues/detail?id=707 上的代码将 System.Drawing.Bitmap 转换为 SlimDX.Direct2D.Bitmap。我用过 E X A C T L Y 之前和之前相同的代码运行良好。现在,当我用
绘制图像时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
【问题讨论】:
【参考方案1】:我解决了。不是真的,但我只是重新翻译了一遍,完全一样,它可以工作。
【讨论】:
以上是关于SlimDX GDI 位图到 Direct2D 位图的比例约为 1.5 - 2 X的主要内容,如果未能解决你的问题,请参考以下文章
将位图 (bmp) 转换为具有透明度的 png (Windows c++)