directx - Can't flip bitmap when calling ID2D1DeviceContext::DrawBitmap -
i have following code draw bitmap on direct2d context:
id2d1devicecontext * pcontext; // initialization omitted id2d1bitmap1 * pbitmap; // initialization omitted pcontext->drawbitmap(pbitmap, null, 1.f, d2d1_interpolation_mode_linear, null, null);
this works fine, need image flipped vertically, tried this:
d2d_matrix_4x4_f flip = d2d1::matrix4x4f::rotationy(180); pcontext->drawbitmap(pbitmap, null, 1.f, d2d1_interpolation_mode_linear, null, &flip);
but bitmap not being drawn @ all. when provide identity matrix instead, works. when try replace y
value in matrix 1
-1
fails again (i believe it's same making rotation matrix in original code snippet).
also tried provide d2d_rect_f
struct destinationrectangle
, , tried switch between top , bottom values in rect - same problem remains.
any insides welcome.
i'm not sure "perspectivetransform" parameter of drawbitmap means, traditional way of using transforms in direct2d work:
const d2d1_size_f& size = pcontext->getsize(); d2d1_point_2f center = d2d1::point2f(size.width / 2.0f, size.height / 2.0f); pcontext->settransform(d2d1::matrix3x2f::rotation(180.0f, center); pcontext->drawbitmap(pbitmap); pcontext->settransform(d2d1::matrix3x2f::identity());
note uses id2d1rendertarget::drawbitmap method, not id2d1devicecontext::drawbitmap (though either 1 should work, don't use perspectivetransform parameter). tested , works.
another way of doing this, perhaps more efficiently, first create wic bitmap (iwicbitmapsource), rotate using iwicbitmapfliprotator, , create id2d1bitmap rotator using id2d1rendertarget::createbitmapfromwicbitmap. demonstration of this, see how flip , rotate bitmap source.
Comments
Post a Comment