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

  • SEARCH
  • Home
  • 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 8498785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:29:48+00:00 2026-06-11T00:29:48+00:00

I have this code to paint with my finger on ipad in bitmap context.

  • 0

I have this code to paint with my finger on ipad in bitmap context. And i’m getting lined (long dots) line instead of full line and the line is flickering when i move my finger, and it doubled in sense that when i move my finger i get two lines on each side of the screen. Any idea what is going on?

Thanks in advance.

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
  UITouch *touch = [touches anyObject];

self.prePreviousPoint = self.previousPoint;
self.previousPoint = [touch previousLocationInView:self];
CGPoint currentPoint = [touch locationInView:self];

// calculate mid point
CGPoint mid1 = [self calculateMidPointForPoint:self.previousPoint andPoint:self.prePreviousPoint];
CGPoint mid2 = [self calculateMidPointForPoint:currentPoint andPoint:self.previousPoint];

//inicijaliziranje contexta u kojem se sve crta
UIGraphicsBeginImageContext(self.drawImageView.frame.size);
// CGContextRef context = UIGraphicsGetCurrentContext();

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
context = CGBitmapContextCreate(NULL, self.drawImageView.frame.size.width, self.drawImageView.frame.size.height, 8, self.drawImageView.frame.size.width*4, colorSpace,kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
UIGraphicsPushContext(context);
CGRect rect = CGRectMake(0, 0, self.drawImageView.frame.size.width, self.drawImageView.frame.size.height);

// setting line color

[[self currentColor] setStroke];

CGContextSetAllowsAntialiasing(context, true);
CGContextSetShouldAntialias(context, true);

//inicijaliziranje viewa u koji se crta slika te odredivanje vrha linije i biljezenje pokreta
[self.drawImageView.image drawInRect:rect];
CGContextMoveToPoint(context, mid1.x, mid1.y);
// Use QuadCurve is the key
CGContextAddQuadCurveToPoint(context, self.previousPoint.x, self.previousPoint.y, mid2.x, mid2.y);

CGContextSetLineCap(context, kCGLineCapRound);

// complete distance variable is used for setting line width in respect of speed of finger movment and time the finger moves

CGFloat xDist = (previousPoint.x - currentPoint.x); //[2]
CGFloat yDist = (previousPoint.y - currentPoint.y); //[3]
CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist)); //[4]

distance = distance / 10;

if (distance > 10) {
    distance = 10.0;
}

distance = distance / 10;
distance = distance * 3;

if (4.0 - distance > self.lineWidth) {
    lineWidth = lineWidth + 0.3;
} else {
    lineWidth = lineWidth - 0.3;
}

CGContextSetLineWidth(context, self.lineWidth);

//    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);

NSLog(@"%@",context);
//Crtanje svega na ekran i "zatvaranje" image contexta
//CGContextDrawImage(context,CGRectMake(0, 0, self.drawImageView.frame.size.width, self.drawImageView.frame.size.height) , image1);
CGContextStrokePath(context);

CGImageRef image = CGBitmapContextCreateImage(context);
image2 = [UIImage imageWithCGImage:image];
//UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
self.drawImageView.image = image2;
UIGraphicsPopContext();
CGImageRelease(image);
NSLog(@"%@ %@",image,image2);
CGContextRelease(context);
UIGraphicsEndImageContext();

}

  • 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-11T00:29:50+00:00Added an answer on June 11, 2026 at 12:29 am
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
     colorSpace = CGColorSpaceCreateDeviceRGB();
    context1 = CGBitmapContextCreate(NULL, self.drawImageView.frame.size.width, self.drawImageView.frame.size.height, 8, self.drawImageView.frame.size.width*4, colorSpace,kCGImageAlphaPremultipliedLast);
    CGColorSpaceRelease(colorSpace);
    
    self.previousPoint = [touch locationInView:self];
    }
    
    
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
     UITouch *touch = [touches anyObject];
    
    self.prePreviousPoint = self.previousPoint;
    self.previousPoint = [touch previousLocationInView:self];
    CGPoint currentPoint = [touch locationInView:self];
    
    // calculate mid point
    CGPoint mid1 = [self calculateMidPointForPoint:self.previousPoint andPoint:self.prePreviousPoint];
    CGPoint mid2 = [self calculateMidPointForPoint:currentPoint andPoint:self.previousPoint];
    
    rect = CGRectMake(0, 0, self.drawImageView.frame.size.width, self.drawImageView.frame.size.height);
    
        UIGraphicsPushContext(context1);
    
      UIGraphicsBeginImageContext(self.drawImageView.frame.size);
      context = UIGraphicsGetCurrentContext();
    
    
      // setting line color
    
    [[self currentColor] setStroke];
    
    CGContextSetAllowsAntialiasing(context, true);
    CGContextSetShouldAntialias(context, true);
    
    [self.drawImageView.image drawInRect:rect];
    
    CGContextMoveToPoint(context, mid1.x, mid1.y);
    // Use QuadCurve is the key
    CGContextAddQuadCurveToPoint(context, self.previousPoint.x, self.previousPoint.y, mid2.x, mid2.y);
    
     CGContextSetLineCap(context, kCGLineCapRound);
    
     // complete distance variable is used for setting line width in respect of speed of finger    movment and time the finger moves
    
    CGFloat xDist = (previousPoint.x - currentPoint.x); //[2]
    CGFloat yDist = (previousPoint.y - currentPoint.y); //[3]
    CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist)); //[4]
    
    distance = distance / 10;
    
    if (distance > 10) {
        distance = 10.0;
    }
    
    distance = distance / 10;
    distance = distance * 3;
    
    if (4.0 - distance > self.lineWidth) {
        lineWidth = lineWidth + 0.3;
    } else {
        lineWidth = lineWidth - 0.3;
    }
    
    CGContextSetLineWidth(context, 15);
    
    //    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
    
     CGContextStrokePath(context);
    
     image = CGBitmapContextCreateImage(context);
     image2 = [UIImage imageWithCGImage:image];
    
    UIGraphicsPopContext();
    UIGraphicsEndImageContext();
    CGContextRelease(context1);
    CGImageRelease(image);
    [drawImageView setImage:image2];
    
    }
    

    This is the entire code that solved my problem i figured it out on my own at the end.

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

Sidebar

Related Questions

I have this code package com.cerbertek; import java.util.ArrayList; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory;
I have found this code for reverse geocoding: var point = new GLatLng (lat[1],long[1]);
Well i have this code to find the paint quality of a room. void
I have this code: def display(self): print self.doc.toprettyxml(indent= ) strigName ='/Users/my_user/Desktop/python/' + str(datetime.datetime.now()) +
I have this code that I want to make point-free; (\k t -> chr
I have this code: public class Area { Texture2D point; Rectangle rect; SpriteBatch _sB;
i have this code in php and it's supposed to print me the image
I have this code in Python inputted = input(Enter in something: ) print(Input is
So I have this code which is called in a print_info() function after a
I have this piece of code in a function. I want to print the

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.