wpf - LinearGradientBrush with gradientstops outside of the line -
i'm trying draw waveform ones used on soundcloud.com in wpf application i'm doing drawing multiple vertical lines
what want lines have same color transition (so horizontally pixels have same color) because not lines have same length each line has different color @ end of line.
the lineargradientbrush has lot of constructors, , 1 suited needs seems lineargradientbrush(gradientstopcollection, point, point).
msdn article on lineargradientcontstructor
with these points seem able set gradientstops outside of drawn line
the problem have don't know how use points.
var r = new gradientstopcollection(); r.add(new gradientstop(colors.black, 0)); r.add(new gradientstop(colors.red, 0.5)); r.add(new gradientstop(colors.black, 1)); //this main gradient background lines (100%) (int = 0; < 25; i++) { var line = new line { x1 = i, x2 = i, y1 = 0, y2 = 200, stroke = new lineargradientbrush(r), strokethickness = 1 }; waveformcanvas.children.add(line); } //this actual value of waveform, points 0,0 , 1,1 seem indicate gradientstops on y1/y2 (int = 25; < 50; i++) { var line = new line { x1 = i, x2 = i, y1 = 50, y2 = 150, stroke = new lineargradientbrush(r, new point(0, 0), new point(1, 1)), strokethickness = 1 }; waveformcanvas.children.add(line); } //these point values seem correct current line length //i came these values trial , error (int = 50; < 75; i++) { var line = new line { x1 = i, x2 = i, y1 = 50, y2 = 150, stroke = new lineargradientbrush(r, new point(-0.5, -0.5), new point(1.5, 1.5)), strokethickness = 1 }; waveformcanvas.children.add(line); }
i'm puzzled why points 2d coordinates because gradient points -0.5,-0.5 not seem have different angle drawn line
so need understand how place points relative "main 100% gradient"
or maybe easier way draw lines in solid colour , afterwards use kind of colour select replace black pixels rectangular gradient background.
take @ gradientbrush.mappingmode property.
lineargradientbrush(gradientstopcollection, point, point)
initialize brush brushmappingmode.relativetoboundingbox
think need brushmappingmode.absolute
. there no constructor overload this. have set property own.
lineargradientbrush brush = new lineargradientbrush(r, new point(0, 0), new point(0, 200)); brush.mappingmode = brushmappingmode.absolute;
Comments
Post a Comment