1

I have for points in 2d space (p1, p2, p3, p4) where I want to draw a shape using them, but also want to fill inside this shape with an Image file (png). I won't have any borders, just the Image itself filling the dimensions of the shape fully.

I will have to draw the shapes 1000s of times a second so anything that's faster would be cool, but the shapes themselves are 50x50 pixels, so not very big.

Any ideas?

Joan Venge
  • 315,713
  • 212
  • 479
  • 689
  • 2
    "I will have to draw the shapes 1000s of times a second" - what kind of users do you have? They can't be human. – H H Apr 22 '11 at 07:54
  • You are funny Henk :O But this is sort of like a for fun game like app that just moves shape in 2d space so I have to draw them fast. In reality it might be lower than 1000, I just approximated it :O – Joan Venge Apr 22 '11 at 23:09
  • @JoanVenge Henk's point is that games/apps generally don't update graphics anywhere close to that often. 60 frames per second is usually considered adequate, and 120 frames per second is considered very, very good. Most monitors won't even support updates more often than that anyway. – Beska Feb 20 '13 at 16:53

2 Answers2

3

You can use an ImageBrush to fill any Rectangle, which uses your points. You just need to set the Rectangle.Fill property to your brush.

This is discussed more here.

CodeNaked
  • 40,753
  • 6
  • 122
  • 148
  • Thanks CodeNaked, but this is for a true rectangle right? Mines are more like polygons with 4 sides, so not all sides are equal in length. Is there a Shape like that I can squeeze an image sort of like pinpointing an image to 4 points, by stretching it if necessary. – Joan Venge Apr 22 '11 at 21:50
  • @Joan - Sorry, missed that. You mention "for" points, but only list two :-) The brush will work for any Polygon also, but you won't be able to easily skew/stretch/transform the image to fit it (i.e. to have the top-left corner match your top-left point and bottom-left match bottom-left, etc). If that's what you mean. – CodeNaked Apr 25 '11 at 11:26
  • Np, you are right. I must be thinking something else, I edited the question now. So yeah 4 points, and was hoping I could skew/stretch it to make the image fit into the polygon, but not behave like a cutout/mask. LIke this one: http://droptutorial.com/wp-content/uploads/2009/09/2465.jpg Though not like it's on another plane, so it will always be mapped to screen, not use another plane if that makes sense. – Joan Venge Apr 26 '11 at 04:17
  • @Joan - Gotcha. That is definitely harder, as you are effectively doing 3D, even if it's using 2D rendering. I'll leave this answer up, so you don't get a similar answer again. – CodeNaked Apr 26 '11 at 11:44
  • I made a version here: http://i55.tinypic.com/14ditf7.png Sorry for the banding, but this is it basically. Pinning an image to 4 points where the image itself "follows" the points. Is it hard to do? I should probably ask a new question for this I guess. – Joan Venge Apr 27 '11 at 16:40
  • 1
    @Joan - Probably doesn't need to be separate question. But yeah, that is more difficult. You either have to render the image to a Rectangle, which you then rotate in a 3D space (or mimic in a 2D space) or orthorectify or use [3D projection](http://en.wikipedia.org/wiki/3D_projection) on the image to fit the polygon. – CodeNaked Apr 28 '11 at 00:55
0

Could you lay a mask over the image that would block all area outside your shape? I'm assuming you don't mean tiling the shape with the image.

Lisa
  • 11
  • 1
  • No the image has to be scaled to fit into this polygonal shape defined by these 4 points. But I see what you mean, so no tiling. – Joan Venge Apr 21 '11 at 23:58