开发者

How to interchange D3DImage between a WPF application and Windows (for Copy/Paste)?

I'm being working in making copy and paste operations on my diagramming application. Therefore, I need to...

  • Convert a WPF Bitmap to a D3DImage (for later implement "Copy"), and

  • Convert a D3DImage to a WPF Bitmap (fo开发者_C百科r later implement "Paste").

Notice that this requieres "Interop" between the WPF Application and the native Win-32.

How to do this, as short as possible (two functions, ideally)?


You probably found your answer in the past half year but here is how to convert a D3DImage in WPF to BitmapSource (I used vb.net in this case):

Public Function GetCurrentImage() As BitmapSource

        Dim width As Integer = D3DImage.PixelWidth
        Dim height As Integer = D3DImage.PixelHeight

        Dim dv As New DrawingVisual()
        Using dc As DrawingContext = dv.RenderOpen()
            dc.DrawImage(D3DImage, New Rect(0, 0, width, height))
        End Using

        Dim rtb As New RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32)
        rtb.Render(dv)

        Return BitmapFrame.Create(rtb)
    End Function

You can find it in C# in the WPFMediaKit.


What do you mean by D3DImage?

There is a 'Control'/Surface in WPF that is named D3DImage but it feels as if you are referring to a bitmap format. Are you trying to put the data on the clipboard? If so you won't need interop. Just use the Clipboard API to put the image on the clipboard and read it from the clipboard.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜