Question

I am wondering which is the best way, in terms of speed and efficiency, to draw a frame around an image on iPhone, especially when I have to draw lots of these images:

1) Drawing the image and then the frame around or 2) Drawing a rect, filling it with a color and then drawing the image within that rect leaving some offset pixel to mimic the frame

Does Quartz draw everything that it is told to or is it smart enough to draw only what is really visible? My feeling is that the first approach is better because there is actually less drawing done. Is it really so?

Thanks P.

Was it helpful?

Solution

Quartz drawing will only take place within the bounds of the view, if you are doing custom drawing in -drawRect:.

That said, I think that you will see the best performance if you simply create UIImageViews for each image, then use the borderWidth, borderColor, and possibly cornerRadius properties on your view's layer to set a border. For example:

imageView.layer.cornerRadius = 10.0f;
imageView.layer.borderWidth = 3.0f;
imageView.layer.borderColor = [[UIColor blackColor] CGColor];

will place a 3-pixel-wide black border around your view, and give it a 10 pixel radius at the corners.

OTHER TIPS

If performance is a problem, you should try to minimize the number of operations you perform on the graphics context, especially the ones that have no visible components.

In your particular case, I think you need to test both options on an iPhone (ist gen if possible) and benchmark them. Maybe it's easier to just fill the whole rectangle rather than calculate which pixels are part of the frame and which aren't?

It depends on the graphics chip.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top