Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8521859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:56:45+00:00 2026-06-11T06:56:45+00:00

I am working on an app, and at some point the user needs to

  • 0

I am working on an app, and at some point the user needs to draw something over an image.
The code i wrote works just fine for images around 1500x1500 and smaller, but once the images get bigger, the problem starts.

When images get too big, it takes more time to do the drawing, and the Gesture Recognizer gets called rarely.

Here’s how I did it: there are two classes, one is a UIScrollView subclass called DrawView and one is a UIImageView subclass called MyPen. DrawView has a UIPanGestureRecognizer that sends messages to MyPen every time it gets recognized (I get the [recognizer state] and depending on it i start or move a line). DrawView has two UIImageView objects in its subviews, one for the background image, and one for the drawings (the pen).

here’s what I do in MyPen:

- (void)beginLine:(CGPoint) currentPoint
{
    previousPoint = currentPoint;
}

- (void)moveLine:(CGPoint) currentPoint
{
    self.image = [self drawLineFromPoint:previousPoint toPoint:currentPoint image:self.image];
    previousPoint = currentPoint;
}

- (UIImage *)drawLineFromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint image:(UIImage *)image
{
CGSize screenSize = self.frame.size;
UIGraphicsBeginImageContext(screenSize);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
[image drawInRect:CGRectMake(0, 0, screenSize.width, screenSize.height)];

CGContextSetLineCap(currentContext, kCGLineCapRound);
CGContextSetLineWidth(currentContext, _thickness);
CGContextSetStrokeColorWithColor(currentContext, _color);
CGContextBeginPath(currentContext);
CGContextMoveToPoint(currentContext, fromPoint.x, fromPoint.y);
CGContextAddLineToPoint(currentContext, toPoint.x, toPoint.y);
CGContextStrokePath(currentContext);

UIImage *ret = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return ret;
}

When the image is big enough, it takes some time for CoreGraphics to render it, and so the gesture recognizer doesn’t get recognized so often, and sends less points to the pen.

The question here is: Is there a way to optimize the drawing? Should I use another Thread for ir ? Is there another way around it ?
Any help greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:56:47+00:00Added an answer on June 11, 2026 at 6:56 am

    You should split foreground (the lines) and the background (the image the lines should be drawn on) into two Views. So you can only update the foreground View every time the user moves his finger. You can compose the two views into one Image when the user finishs drawing.

    Drawing an image inside a CGContext is very expensive, especialy when large.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on app that needs user interaction to locate some points in image.
I have my php app working fine, performing some other Graph API functions. However,
I am working on an app featuring some measurements entered by human operators. In
I'm working on an app that does some web scraping. In the sites model,
I've been working with app engine for quite some time, I know that there
I'm working on an app that has some forms that are contained within a
I'm working on a PyGTK app with some Buttons that, when clicked, give a
Hi I am working on an app that adds some features to etherpad lite.
I am working on some scraping app, i wanted to try to get it
I'm working on an app using Bluetooth discovery pretty heavily (some detail here ).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.