jingwood / d2dlib

A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
MIT License
245 stars 43 forks source link

load bitmaps on a thread to store them in a list #27

Open BergChristian opened 4 years ago

BergChristian commented 4 years ago

Hi,

I have been trying out your lib. Very nice!

I have built my own thumbnail viewer in .net. It is very fast due to blitting but I am thinking to use your lib as the backend instead. But I had a question. Can I blit/copy/move and area of the screen to another part of the screen so I only have render the new part?

All the best Christian

jingwood commented 4 years ago

Thanks! Help this library helps you.

To draw a part of image, you can:

  1. Create an empty memory image
  2. Draw a part of origin image into the memory image
  3. Draw the memory image on screen

There is an example program at https://github.com/jingwood/d2dlib/blob/master/src/Examples/Demos/ImageTest.cs#L86-L92

The result: imagetest

BergChristian commented 4 years ago

Hi again

So I have learned more :) but a question again.

When scrolling a thumbnail viewer I have previously copied the existing frame to the new frame but with a couple of pixels offset to avoid having to draw the same Thing again and save a lot of time.

Is there an equivalent function in Direct2D or is the idea that you draw the bitmap on itself with an offset, add the new missing part and the. Paint the new version of it to the screen?

All the best Christian

jingwood commented 4 years ago

Hi Christian! How large is your thumbnail image?

Except you have a very large thumbnail image or infinite content, like a side-scrolling video game. With Direct2D, I think you don't need to implement the scroll using some low-level operations like bitblt yourself, you may just draw the entire thumbnail image within the viewport window by an offset or transform.

You can see the example code at: https://github.com/jingwood/d2dlib/blob/master/src/Examples/Demos/Subtitle.cs

BergChristian commented 4 years ago

You are right! I tried it and once I get it going a little Better I will share Some code here.

In the meantime I am struggling if it is possible To load the thumbnails on a separate thread.

The idea is that I preload thumbnails to the memory as they come but to avoid waiting for a thumbnail I can load it in a thread and display an empty box in between. Once it is loaded it is drawn to the screen.

Can you point me to an example or a mechanism to be able to load bitmaps on a thread to store them in a list or so.