Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save a rendered bitmap? (Read back a rendered image) #44

Open
BergChristian opened this issue Jan 14, 2021 · 6 comments
Open

Save a rendered bitmap? (Read back a rendered image) #44

BergChristian opened this issue Jan 14, 2021 · 6 comments
Labels

Comments

@BergChristian
Copy link

Hi again!

Once again... Amazing lib 馃憤

I am trying to find out a way to render the screen to a bitmap (to save it). Cant really figure it out how to do it, can you point me in the right direction?

Thanks
Christian

@BergChristian
Copy link
Author

Hi!

I found this article. Is there any help in getting the content on the screen into a bitmap (on disk or in memory to save or export)?

https://www.programmersought.com/article/84934931885/

best
Christian

@jingwood
Copy link
Owner

jingwood commented Jan 17, 2021

Do you mean to capture the entire screen? or just the view of your application window.

If the entire screen you can consider to use a simple way like this:
https://stackoverflow.com/questions/5049122/capture-the-screen-shot-using-net

Direct2D uses GPU memory so there is no easy way to get a Direct2D rendered result, you should render your entire scene into a memory bitmap, and use the bitmap for what you want, show the bitmap on screen, or saving the bitmap onto disk.

@BergChristian
Copy link
Author

Hi!

The second option would be great. Is there a way to create a bitmap, render the scene to it instead of the scene and the save the bitmap?

in GDI what I did was that instead of sending the graphics object of the form/user control I created a bitmap and created a graphics object of it and send that one to the scene renderer.

I am imaging I could do the same here? And then how do I get the bitmap from the D2Dbitmap object. Sort of the reverse of convertGDIbitmaptoD2Dbitmap.

All the best!

Christian

@jingwood jingwood changed the title Rending the view to a bitmap? Rendering the view to a bitmap? Feb 22, 2021
@jingwood jingwood changed the title Rendering the view to a bitmap? Save a rendered bitmap? (Read back a rendered image) Feb 22, 2021
@jingwood
Copy link
Owner

jingwood commented Apr 8, 2021

Similar to #27, #61

@dvoris
Copy link

dvoris commented Dec 16, 2021

Hello! I am looking for a way to save the drawn D2Dbitmap to disk. Please, help me

@Paliscope
Copy link

Hi @dvoris.
This is what I use to save. It really copies the screen to a bitmap so make sure you don't have anything in front of your area.

Public Shared Function CaptureWindow(ctrl As Control) As Bitmap

    Try

        Dim desktophWnd As IntPtr
        Dim desktopDc As IntPtr
        Dim memoryDc As IntPtr
        Dim bitmap As IntPtr
        Dim oldBitmap As IntPtr
        Dim success As Boolean
        Dim img As Bitmap

        desktophWnd = GetDesktopWindow()
        desktopDc = GetWindowDC(desktophWnd)
        memoryDc = CreateCompatibleDC(desktopDc)
        bitmap = CreateCompatibleBitmap(desktopDc, ctrl.Width, ctrl.Height)
        oldBitmap = SelectObject(memoryDc, bitmap)

        success = BitBlt(memoryDc, 0, 0, ctrl.Width, ctrl.Height, desktopDc, ctrl.PointToScreen(New Point(0, 0)).X, ctrl.PointToScreen(New Point(0, 0)).Y, RasterOperations.SRCCOPY Or RasterOperations.CAPTUREBLT)

        img = Image.FromHbitmap(bitmap)




        SelectObject(memoryDc, oldBitmap)
        DeleteObject(bitmap)
        DeleteDC(memoryDc)
        ReleaseDC(desktophWnd, desktopDc)

        Return img

    Catch ex As Exception

    End Try

End Function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants