d2phap / DXControl

🖌️ A WinForms hybrid control that supports Direct2D and GDI+ drawing
MIT License
24 stars 5 forks source link

How to get pixel color? #4

Closed Charltsing closed 2 months ago

Charltsing commented 2 months ago

I want to obtain the current pixel color in the mouse event on the canvas, How to get pixel color in it? (not from bitmap)

d2phap commented 2 months ago

You need to copy bitmap data from GPU to CPU, then use ID2D1Bitmap1.Map() method.

See https://github.com/d2phap/ImageGlass/blob/e2045cb557300df4260e3374554efa0597bee561/Source/Components/ImageGlass.Base/BHelper/Extensions/ID2D1Bitmap1Extensions.cs#L33-L76

Charltsing commented 2 months ago

Thank you,i try it , the speed of converting image formats is slow and memory usage is high

I try 3300x12000, 12M image

捕获

Charltsing commented 2 months ago

how to use copypixels in WIC ? perhaps this can be faster?

https://learn.microsoft.com/en-us/windows/win32/api/wincodec/nf-wincodec-iwicbitmapsource-copypixels

d2phap commented 2 months ago

This library is just provide Direct2D API for WinForms, to start building something with this, you need to learn Direct2D.

how to use copypixels in WIC ? perhaps this can be faster?

This question is not related to this library. You need to try and check by yourself.