Subscribe ( )

iPhone Programming Tutorials

 

Forum

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

You must be logged in to post Login Register

Search 

Graphics drawing versus images

User Post

8:52 pm
November 16, 2008


janoss

Noob

posts 2

1

I am new to the iPhone SDK and am looking for best practiced on doing graphics.

I want to create a simulated compass that moves as new location info is received from an external compass device. I know that can draw the compass using the CGContextRef and CGContextFillEllipseInRect methods and redraw as the compass data changes. Seems like alot of overhead.

My question is, is it the iPhone sdk best practice to create an PNG image then use this image in a UIImageView and manipulate the image?  ie, rotate it as new data is received.

I think the answer is to use the PNG based on the Apple Metronome sample.


by the way, Excellent iPhone sdk tutorial site.

11:41 am
November 18, 2008


VertigoSol

Moderator

posts 26

2

the png is that fastest way to do this but you could just as easily
draw it by hand. if you will only be drawing it once or a couple times uses a UIImage if your image is consistently changing use Core Graphics to draw it

10:08 pm
November 18, 2008


janoss

Noob

posts 2

3

I took your advice and used the CG to draw my initial image.

This draws a circle, would it be best to now add this image to a Layer and then an LKTransform to rotate the transform as needed based on heading info?


The following code is what I have for drawing the inital image.

    const double RADIUS = rect.size.width/2.0;
    const int offset = 45;
    const int lineWidth = 2;
    azimuth = 170;
    lastAzimuthRadians = 0;
   
    //convert degrees to radians to use trigonometric functions.
    double azimuthRadians = azimuth * (M_PI / 180.0);
    CGContextRef context = UIGraphicsGetCurrentContext();
   
    //Draw the circle
    CGContextSetRGBStrokeColor(context, 255, 255, 255, 1.0);
    CGContextSetLineWidth(context, lineWidth);
    CGContextAddEllipseInRect(context, CGRectMake(3.0, offset, (RADIUS*2)-6.0, (RADIUS*2)-6.0));
    CGContextStrokePath(context);



About the iCodeBlog forum

Currently Online:

3 Guests

Maximum Online: 25

Forums:

Groups: 2

Forums: 6

Topics: 305

Posts: 743

Members:

There are 654 members

There are 1 guests


Brandon has made 87 posts

Top Posters:

bobcubsfan - 53

crazyiez - 30

VertigoSol - 26

Uhu - 17

AdeC - 17

Administrator: Brandon | Moderators: VertigoSol


© - Version 3.1.4 (Build 357)