Friday, 15 May 2015

vb.net - Exclude Area within a Graphics Path -



vb.net - Exclude Area within a Graphics Path -

i working gdi , trying draw object top view. want draw round footstool feet when top see feet outside of main circle.

i see plenty of examples of clipping outside want clip every thing within circle , paint circle outline.

here sample code demo i'm trying do. easy , i've tried including region.exclude cant work.

dim bmp new bitmap(500, 500) dim g graphics = graphics.fromimage(bmp) g.clear(color.transparent) g.smoothingmode = smoothingmode.highquality g.pixeloffsetmode = pixeloffsetmode.default ' add together 4 feet dim npoints point() = {new point(50, 5), new point(95, 50), new point(50, 95), new point(5, 50), _ new point(5, 5), new point(90, 90), new point(0, 0), new point(100, 100)} dim gp new graphicspath dim p pen = new pen(color.darkgray, 1) dim feetsize size = new size(10, 10) integer = 0 3 gp.addellipse(new rectangle(new point(npoints(i).x - (feetsize.width / 2), npoints(i).y - (feetsize.height / 2)), feetsize)) next g.drawpath(p, gp) ' want clipping now; ie within circle part below ' draw main footstool circle gp.reset() gp.addellipse(npoints(4).x, npoints(4).y, npoints(5).x, npoints(5).y) g.drawpath(p, gp) ' set picturebox value picturebox1.image = bmp

[update] found solution using graphics.excludeclip:

' add together feet dim p pen = new pen(color.darkgray, 1) dim feetsize size = new size(10, 10) integer = 0 3 gp.addellipse(new rectangle(new point(npoints(i).x - (feetsize.width / 2), npoints(i).y - (feetsize.height / 2)), feetsize)) next ' clip exclude circle dim egp new graphicspath egp.addellipse(npoints(4).x, npoints(4).y, npoints(5).x, npoints(5).y) g.excludeclip(new region(egp)) ' draw result g.drawpath(p, gp) ' draw circle g.resetclip() gp.reset() gp.addellipse(npoints(4).x, npoints(4).y, npoints(5).x, npoints(5).y) g.fillpath(new solidbrush(fillcolour), gp) g.drawpath(p, gp)

vb.net gdi

No comments:

Post a Comment