开发者

Drawing Lines Between Points In UIImage

I have an XML file like:

<PointCollection>
<Point x="2453.553575623344" y="1011.755461592671"/>
<Poin开发者_StackOverflowt x="2260.662874593102" y="1102.865398167724"/>
<Point x="2259.547233128629" y="1276.871740662439"/>
<Point x="2293.490150676198" y="1444.799859055673"/>
<Point x="2375.667740528206" y="1696.692036645525"/>
<Point x="2480.350615792477" y="1865.216215309236"/>
<Point x="2757.972180274506" y="1877.125440451022"/>
<Point x="2939.521225544476" y="1715.15279036209"/>
<Point x="3052.739622134972" y="1443.013389711065"/>
<Point x="2997.359072452096" y="1135.740662438337"/>
<Point x="2774.050404375987" y="1030.338971106413"/>
</PointCollection>

I need to draw lines between these points and create a shape over UIIMage to annotate a specific area on that image.For example I m going to draw a line between Point x="2453.553575623344" y="1011.755461592671" and Point x="2260.662874593102" y="1102.865398167724" which have x and y coordinates according to the resolution of the image. How can i do this? Thank you.


In brief, you should:

  • Figure out how much of the model space you want to display in your image.
  • From within the drawing context, get the current CGContextRef (UIGraphicsGetCurrentContext() on iOS).
  • Translate and scale your coordinate system by manipulating the Current Transformation Matrix (CTM) so that you can draw in terms of the model coordinates rather than the bitmap coordinates. Changing the coordinate system for your drawing lets the system do all the math to fit your lines into the actual bits of the image.
  • Then, repeatedly:
    • Use a CGPath/CGMutablePath to describe a shape.
    • Set a stroke/fill color (or any of many other settings).
    • Stroke/fill the path as appropriate.

Note that, if you are drawing over an existing image rather than creating a wholly-new image, you might want to draw the current image over the blank canvas prior to transforming the CTM.

You might not understand any of this till you read about drawing using CoreGraphics. Check out the Quartz 2D Programming Guide for a good survey of drawing 2D images using CoreGraphics.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜