c++ - Direct2D: Convert ID2D1Image to ID2D1Bitmap -
i'm working on programm needs modify on screen. have id2d1bitmap
created using prendertarget->copyfromrendertarget
.
what i'm trying is, applying effects bitmap. effect returns id2d1image
, need have id2d1bitmap
.
is there way this?
edit1:
id2d1bitmap* mybitmap //the bitmap want apply effect id2d1effect* effect = null; pdevicecontext->createeffect(clsid_d2d1saturation, &effect); effect->setvalue(d2d1_saturation_prop_saturation, 0.0f); effect->setinput(0, mybitmap); id2d1image* pimg = null; effect->getoutput(&pimg);
if cast image, getpixelsize() raises access violation.
i solved it. it's dirty, works.
id2d1bitmap* convertimagetobitmap(id2d1image* pimg, d2d1_size_u size) { id2d1image* oldtarget = null; id2d1bitmap1* targetbitmap = null; //create bitmap "d2d1_bitmap_options_target" d2d1_bitmap_properties1 bitmapproperties = d2d1::bitmapproperties1( d2d1_bitmap_options_target, d2d1::pixelformat(dxgi_format_b8g8r8a8_unorm, d2d1_alpha_mode_premultiplied) ); pdevicecontext->createbitmap(size, 0, 0, bitmapproperties, &targetbitmap); //save current target, replace id2d1bitmap pdevicecontext->gettarget(&oldtarget); pdevicecontext->settarget(targetbitmap); //draw image on target (if not drawing call begin/enddraw) pdevicecontext->drawimage(pimg); //set previous target pdevicecontext->settarget(oldtarget); oldtarget->release(); return targetbitmap; }
Comments
Post a Comment