Resizing a DXGI Resource or Texture2D in SharpDX

前端 未结 3 1156
盖世英雄少女心
盖世英雄少女心 2021-01-05 04:05

I want to resize a screen captured using the Desktop Duplication API in SharpDX. I am using the Screen Capture sample code from the SharpDX Samples repository, relevant port

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-05 04:19

    Here is a pixelate example...

    d2d_device_context_h()->BeginDraw();
    d2d_device_context_h()->SetTarget(mp_ppBitmap1.Get());
    D2D1_SIZE_F rtSize = mp_ppBitmap1->GetSize();
    rtSize.height *= (1.0f / cbpx.iPixelsize.y);
    rtSize.width *= (1.0f / cbpx.iPixelsize.x);
    D2D1_RECT_F rtRect = { 0.0f, 0.0f, rtSize.width, rtSize.height };
    D2D1_SIZE_F rsSize = mp_ppBitmap0->GetSize();
    D2D1_RECT_F rsRect = { 0.0f, 0.0f, rsSize.width, rsSize.height };
    d2d_device_context_h()->DrawBitmap(mp_ppBitmap0.Get(), &rtRect, 1.0f, 
    D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, &rsRect);
    d2d_device_context_h()->SetTarget(mp_ppBitmap0.Get());
    d2d_device_context_h()->DrawBitmap(mp_ppBitmap1.Get(), &rsRect, 1.0f, 
    D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &rtRect);
    d2d_device_context_h()->EndDraw();
    

    Where iPixelsize.xy is the size of the "pixelated pixel", note that i just use linear interpolation when shrinking the bmp and NOT when i reenlarge. This will generate a pixelation effect.

提交回复
热议问题