I want to take a given bitmap image and make my grayscale / black and white presentation as an opacity mask on a drawing context I want to use in
I got enough amount of color to convert, so I ended up with the follwing state of a demo application:
Method on ViewModel:
Public Zero Demo () {var width = 400; Var Height = 400; Var Target = New RenderTargetBitmap (Width, Height, 96, 96, Pixel Formats. Pggra32); Var target2 = New RenderTargetBitmap (width, height, 96, 96, pixel format. Pggra32); Var DrawingVisual = New DrawingWeight (); Var DrawingVisual 2 = New DrawingVisual (); (Var DrawingContact = DrawingVisual.Renderer Open ()) using {var bitmap image = new bitmap image (new uriy (@ "pack: // app: ,,,, / WarningFilled.png")); (Var DrawingContact2 = DrawingVision 2. Using Reader Open ()) {drawingContext2.DrawImage (bitmap image, new rack (0, 0, width, height)); } Goal 2. Render (drawing visual 2); Var mask = target 2. Togracec (); this. Mask = mask; DrawingContext.PushOpacityMask (new ImageBrush (mask)); DrawingContext.DrawRectangle (Brush Reed, Blank, New Rectangle (0, 0, width, height)); // drawingcontext Pop (); } aim. Raider (drawing visual); This.Rendered = Target; }
See:
& lt; Window x: Class = "WpfApplication1.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/ 2006/xaml/Presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ Xaml "xmlns: wpfApplication1 =" clr- namespace: wpfApplication1 "title =" mainwindow "height =" 350 "width =" 525 "& gt; & Lt; Window.DataContext & gt; & Lt; WpfApplication1: MainViewModel & gt; & Lt; / WpfApplication1: MainViewModel & gt; & Lt; /Window.DataContext> & Lt; Grid & gt; & Lt; Grid.ColumnDefinitions & gt; & Lt; Column width = "Auto" /> & Lt; Column width = "Auto" /> & Lt; /Grid.ColumnDefinitions> & Lt; Border grid Column = "0" border area = "2" borderline = "blue" horizontal align = "center" & gt; & Lt; Image source = "{binding render}" width = "400" height = "400" & gt; & Lt; / Image & gt; & Lt; / Border & gt; & Lt; Border grid Column = "1" border = 2 "borderline =" green "horizontal alignment =" center "& gt; image source =" {binding mask} "width =" 400 "height =" 400 "> ; / Image & gt; & lt; / border & gt; & lt; / grid & gt;
Running a demo application produces:
Before I painted the real rectangle, the ambiguity mask pushed to the drawing context Left to reflect The red rectangle is expected.
The bitmap image after the color conversion you see on the right, before it is pushed as an opacity mask as I mentioned it Earlier I used it with black / white conversion, but there was no effect with only two colors.
I have tried many similar setups and scenarios, but I do not have ambiguity To get the mask working.
Article on MSDN (emphasis my):
To create an ambiguity mask, you apply the brushes on an element or ambiguity mask property of the scene. The brush is mapped to an element or view, and the ambiguity value of each brush pixel is used to determine the resulting ambiguity of the element or the pixel of each scene.
Pixel color values are ignored.
No comments:
Post a Comment