c# - Merge Brush and BitmapImage Together -
i'm trying take brush applied button's background , render bitmapimage ontop of it, merging images , setting background.
rendertargetbitmap source = new rendertargetbitmap(convert.toint32(button.rendersize.width), convert.toint32(button.rendersize.height), 96, 96, pixelformats.pbgra32); drawingvisual visual = new drawingvisual(); using (drawingcontext drawingcontext = visual.renderopen()) { drawingcontext.drawrectangle(button.background, null, new rect(new point(0, 0), new point(button.rendersize.width, button.rendersize.height))); drawingcontext.close(); source.render(visual); } visual = new drawingvisual(); using (drawingcontext context = visual.renderopen()) { context.drawimage(source, new rect()); context.drawimage(image, new rect()); context.close(); } source.render(visual);
however, cannot set rendertargetbitmap background property of button. i'm not sure if best way of doing such thing.
if can convert rendertargetbitmap brush, effective approach?
cheers.
we have many ways using codebehind, try use xaml code here. idea using drawingbrush
background. brush requires drawing
. can use drawinggroup
here, because allows append multiple drawings. care geometrydrawing
, imagedrawing
here. geometrydrawing
can render brush using simple rectanglegeometry
while imagedrawing
can render image. here sample xaml code, suppose put inputs including input brush
, input image
resources:
<drawingbrush> <drawingbrush.drawing> <drawinggroup> <geometrydrawing brush="{staticresource somebrush}"> <geometrydrawing.geometry> <rectanglegeometry rect="0,0,1,1"/> </geometrydrawing.geometry> </geometrydrawing> <imagedrawing imagesource="{staticresource someimage}" rect="0,0,1,1"/> </drawinggroup> </drawingbrush.drawing> </drawingbrush>
note when using above brush background, fill whole element. rect
not important here, can set (for both rectanglegeometry , imagedrawing) same value. when set tiled background, rect may important care about. should set other value.
in code above, imagedrawing
declared after geometrydrawing
rendered on top of geometrydrawing
. means later declared drawings on top of before ones. here result in declared geometrydrawing
(rendering lineargradientbrush
green red) after imagedrawing
can see transparent effect of lineargradientbrush:
Comments
Post a Comment