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 7032765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:58:38+00:00 2026-05-28T00:58:38+00:00

What I am doing is on every touch event I am creating an image

  • 0

What I am doing is on every touch event I am creating an image from unsigned char *. Here is my function

-(void)paint:(ImageWarper::WarpedImage *)warpedImg isCircleRequired:(bool)doDrawCircle atPoint:(CGPoint)pt{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if(!mWarper) 
    return;
unsigned char *pixelData = warpedImg->Image.Data;
int imageHeight  = warpedImg->Image.Height;
int scanWidth = warpedImg->Image.ScanWidth;
int imageWidth = warpedImg->Image.Width;
CGDataProviderRef provider = CGDataProviderCreateWithData(
                                                          NULL, 
                                                          pixelData, 
                                                          imageHeight * scanWidth, 
                                                          (CGDataProviderReleaseDataCallback)&freeRawData); 
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
int bytesPerPixel = warpedImg->Image.Bpp;
CGImageRef imageRef = CGImageCreate(imageWidth,
                                    imageHeight,
                                    BitsPerComponent,
                                    bytesPerPixel * BitsPerComponent,
                                    scanWidth,
                                    colorSpaceRef,
                                    bitmapInfo,
                                    provider,
                                    NULL,
                                    YES,
                                    renderingIntent);
if(!imageRef)
    return;

UIImage *uiImage = [UIImage imageWithCGImage:imageRef];
imgScrollView.imgView.image = uiImage;
UIGraphicsBeginImageContext(mbmpImage.size); 
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 1.5);
CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);

[mbmpImage drawInRect:CGRectMake(0, 0, mbmpImage.size.width, mbmpImage.size.height)];

[uiImage drawInRect:CGRectMake(warpedImg->Position.X, warpedImg->Position.Y, warpedImg->Image.Width, warpedImg->Image.Height)];         

if(doDrawCircle){
    [mbmpImage release];
    mbmpImage = [UIGraphicsGetImageFromCurrentImageContext() retain];       

    CGContextStrokeEllipseInRect(ctx,CGRectMake(pt.x - mRadius, pt.y - mRadius, mRadius*2, mRadius*2));
}
else{
    [mbmpImage release];
    mbmpImage = [UIGraphicsGetImageFromCurrentImageContext() retain];
}
UIImage * resultingImage = [UIGraphicsGetImageFromCurrentImageContext() retain];    

UIGraphicsEndImageContext();
imgScrollView.imgView.image =  resultingImage ;

if(!doDrawCircle)   {   
    [mbmpImage release];
    mbmpImage = [resultingImage retain];

}
if(doDrawCircle){
    CGPoint pt2 = [self.view convertPoint:pt fromView:imgScrollView];
    imgPreview.hidden = NO;
    [self addText:mbmpImage text: @"+" atPoint:pt atRect:(warpedImg->Position.X, warpedImg->Position.Y, warpedImg->Image.Width, warpedImg->Image.Height)];
}
else{
    [popoverController dismissPopoverAnimated:YES];
}
[resultingImage release];
CGColorSpaceRelease(colorSpaceRef);
CGDataProviderRelease(provider);
CGImageRelease(imageRef);

[pool drain];
 }

This Function is called as follows:

NSMutableDictionary *d = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[NSValue valueWithPointer:wp1],@"warper", @"YES",@"isCircleRequired",
                                  [NSValue valueWithCGPoint:location],@"point",nil];
[self performSelector:@selector(paintDic:) withObject:d];
[d release];
wp1 = nil;

-(void)paintDic:(NSMutableDictionary *)dictionary{
ImageWarper::WarpedImage *wp1 =  (ImageWarper::WarpedImage *)[[dictionary objectForKey:@"warper"] pointerValue];
[self paint:wp1
    isCircleRequired:[dictionary objectForKey:@"isCircleRequired"] 
    atPoint:[[dictionary objectForKey:@"point"] CGPointValue]];
}

I am using following callback function to release data.

void freeRawData(void *info, const void *data, size_t size) {
data = nil;
}

Can any one help me how do I optimize the speed of this. It is working fine on new iphone but not older iphones.

I am calling paint in perform selector so that I dont get hold of execution while it completes its creation of images.
Also any help to create images directly from raw data i.e. unsigned char * will be 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-05-28T00:58:39+00:00Added an answer on May 28, 2026 at 12:58 am

    Before you attempt any optimizations, measure where you spend your time. Instruments’ performance tools will help you here.

    Off the top of my head, I see a bit of stuff that really need not be there in the code you showed:

    • First and foremost: if you can get away with drawing less often, then do that.
    • The probability that your device’s colorspace changes during the life-time of your app can be neglected — cacheing the color space in a static variable might shave some time off this code.
    • You’re already doing CG-level drawing — not creating UIImages but using CGContextDrawImage instead might save you quite some time, too.
    • If you need not support iOS 3, use dispatch_async instead of performSelector:withObject: — that way you don’t need to wrap and unwrap your non-object types.

    But like I said:

    Measure your app before performing any optimizations!

    Including these measures, I also reduced the number of run loops this code was executed. This measure improved performance of my app drastically.

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

Sidebar

Related Questions

Here is the story. I was doing a program, every time the program is
i am doing a continuously select every 10seconds, so i thought i would do
We're doing a full backup of each of our production databases every night. We
I'm doing a windows form and would like an audit task to happen every
I'm doing some experimenting with this malicious JavaScript line: var undefined = true; Every
Alright, after doing a ton of research and trying almost every managed CPP Redist
We use a CruiseControl.Net/NAnt/Subversion stack for CI. Doing a fresh checkout for every build
Doing odd/even styling with jQuery is pretty easy: $(function() { $(.oddeven tbody tr:odd).addClass(odd); $(.oddeven
I am doing the final touch ups on an app and I am getting
I am making an AJAX request for XML. I am doing this every second.

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.