Drawing ID2D1Image on specified rectangle like DrawBitmap()

thebluetropics 1,046 Reputation points
2022-10-05T23:50:43+00:00

I can do this with ID2D1Bitmap:

   D2D1_SIZE_F clientSize = d2dDeviceContext->GetSize();  
     
   d2dDeviceContext->DrawBitmap(  
     d2dBitmap,  
     D2D1::RectF(100, 0, clientSize.width, clientSize.height)  
   );  

But not with ID2D1Image. All ID2D1DeviceContext::DrawImage() methods only accept image rectangle, not the destination rectangle, which causes cropped image in the client area instead of drawing on the specified rect in the client area.

Is there any equivalent method to the DrawBitmap() above with DrawImage()?

Note that I only had ID2D1Image, using it with DrawBitmap() is impossible.

Edit: Maybe, the only possible way is to convert ID2D1Image to ID2D1Bitmap, but how?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
0 comments No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 14,751 Reputation points Microsoft Vendor
    2022-10-06T08:35:59.327+00:00

    Hello @thebluetropics ,
    Welcome to Microsoft Q&A!

    About the way about convert ID2D1Image to ID2D1Bitmap.

    You can refer to the workaround in StackOverflow: https://stackoverflow.com/questions/31118397/direct2d-convert-id2d1image-to-id2d1bitmap.

    Thank you.
    Junjie


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Castorix31 81,721 Reputation points
    2022-10-06T08:20:40.463+00:00

    There is the D2D1::Point2F parameter + eventually D2D1_RECT_F

    For example in this test, I display with DrawImage the original image at default location, then with GaussianBlur at D2D1::Point2F(300, 0)
    (with D2D1_RECT_F at image size, that can be resized with Scale effect) :

    247979-direct2d-gaussianblur.jpg

    1 person found this answer helpful.