Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm in the process of making a vector drawing application and let me tell you, this is NOT a trivial task to do correctly and requires quite a bit of work.</p> <p>Some issues to keep in mind:</p> <ul> <li>If you are not using vector graphics (CGPaths, for example, are vectors) you will NOT be able to remove the pixelation. A UIImage, for example, only has so much resolution.</li> <li>In order to get your drawing to not look pixelated, you are going to have to redraw everything. If you have a lot of drawing, this can be an expensive task to perform.</li> <li>Having good resolution WHILE zooming is nearly impossible because it would require an excessively large context and your drawing would likely exceed the capabilities of the device</li> </ul> <p>I use core graphics to do my drawing, so the way I solved this issue was by allocating and managing multiple CGContexts and using them as buffers. I have one context that is ALWAYS kept at my least zoomed level (scale factor of 1). That context is drawn into at all times and makes it so that when unzooming completely, no time is spent redrawing since it is already done. Another context is used soley for drawing when zoomed. When not zoomed, that context is ignored (since it will have to be redrawn based on the new zoom level anyway). A high level algorithm for how I perform my zooming is as follows:</p> <pre><code>- (IBAction)handlePinchGesture:(UIGestureRecognizer *)sender { if(sender.state == UIGestureRecognizerStateBegan) { //draw an image from the unzoomedContext into my current view //set the scale transformation of my current view to be equal to "currentZoom", a property of the view that keeps track of the actual zoom level } else if(sender.state == UIGestureRecognizerStateChanged) { //determine the new zoom level and transform the current view, keeping track in the currentZoom property //zooming will be pixelated. } else if(sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled) { if(currentZoom == 1.0) { //you are done because the unzoomedContext image is already drawn into the view! } else { //you are zoomed in and will have to do special drawing //perform drawing into your zoomedContext //scale the zoomedContext //set the scale of your current view to be equal to 1.0 //draw the zoomedContext into the current view. It will not be pixelated! //any drawing done while zoomed needs to be "scaled" based on your current zoom and translation amounts and drawn into both contexts } } } </code></pre> <p>This gets even more complicated for me because I have additional buffers for the buffers because drawing images of my paths is much faster than drawing paths when there is lots of drawing.</p> <p>Between managing multiple contexts, tweaking your code to draw efficiently into multiple contexts, following proper OOD, scaling new drawing based on your current zoom and translation, etc, this is a mountain of a task. Hopefully this either motivates you and puts you on the right track, or you decide that getting rid of that pixelation isn't worth the effort :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload