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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:45:40+00:00 2026-06-01T07:45:40+00:00

In my app, user is allowed to take a photo from a device or

  • 0

In my app, user is allowed to take a photo from a device or upload it from the library to set it as his profile pic. Now when user is done, I need to upload that image to server. Usually the image taken from device is of size 5-6MB. I need it to compress to 25KB before uploading to server. So I am using following method to that

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    [picker release];
    profilePicImageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    NSData* pngData = UIImagePNGRepresentation(profilePicImageView.image);
    NSLog(@"image size of png is %d", [pngData length]);
    NSData *imageData = UIImageJPEGRepresentation(profilePicImageView.image, 0.00001);
    NSLog(@"image size is %d", [imageData length]);
}

Problem with this method is, no matter how small I set the scaling parameter, compressed file size does not drop below ~230KB, which is nearly 10 times higher than what I need.

What is wrong with the above method? Can’t I compress image to 25KB?

Any help, suggestion will be 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-01T07:45:42+00:00Added an answer on June 1, 2026 at 7:45 am

    I think Below code may help you to do what you want, please remove some of my code before using in your app.

    - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
    {
      [appDelegate.objList setHidden:FALSE];    
      [self dismissModalViewControllerAnimated:YES];
    
    UIImage *capturedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [self performSelector:@selector(waitUntillImageCaptured:) withObject:capturedImage afterDelay:0.2];
    }
    
    -(void)waitUntillImageCaptured:(UIImage *)originalImage
    {
    UIImage *tempimg = originalImage;
    //UIImageWriteToSavedPhotosAlbum(tempimg,nil,nil,nil);
    
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
    CGSize newSize = CGSizeMake(320, 480);
    UIGraphicsBeginImageContext(newSize);
    
    [tempimg drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    // End the context
    UIGraphicsEndImageContext();
    
    NSString *strUser = [NSString stringWithFormat:@"%@",[imgDictName objectForKey:@"UsersName"]];
    strUser = [strUser stringByReplacingOccurrencesOfString:@" " withString:@""];
    [strUser retain];
    NSString * strUserLocal = [strUser stringByAppendingString:@"temp.png"];
    
    NSString *imagePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:strUserLocal];
    UIImageView *tempView = [[UIImageView alloc] initWithImage:newImage];
    NSData *data = [NSData dataWithData:UIImagePNGRepresentation(tempView.image)];
    [tempView release];
    
    if(data != nil) {
        [data writeToFile:imagePath atomically:YES];
    }
    else{
        [[NSFileManager defaultManager] removeItemAtPath:imagePath error:NULL];
    }
    
    [pool release];
    
    [self performSelector:@selector(thumbWithSideOfLength:) withObject:strUser afterDelay:0.3];
    }
    
    - (void)thumbWithSideOfLength:(NSString*)strImgName 
    {    
    [self onEditing];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    NSString *fullPathToThumbImage = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@temp.png", strImgName]];
    
    UIImage *thumbnail;
    
    UIImage *mainImage = [UIImage imageWithContentsOfFile:fullPathToThumbImage];
    
    UIImageView *mainImageView = [[UIImageView alloc] initWithImage:mainImage];
    
    CGRect clippedRect = CGRectMake(0, 0, mainImage.size.width,  mainImage.size.height);
    
    CGFloat scaleFactor = 0.8;
    
    UIGraphicsBeginImageContext(CGSizeMake(mainImage.size.width * scaleFactor, mainImage.size.height * scaleFactor));
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
    
    CGContextClipToRect(currentContext, clippedRect);   
    
    CGContextScaleCTM(currentContext, scaleFactor, scaleFactor);
    
    [mainImageView.layer renderInContext:currentContext];
    
    thumbnail = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    NSData *imageData = UIImagePNGRepresentation(thumbnail);
    
    [imageData writeToFile:fullPathToThumbImage atomically:YES];
    userImageView.backgroundColor = [UIColor clearColor];
    [userImageView imageFromImagePath:fullPathToThumbImage];
    
    [mainImageView release];
    }
    

    This will surely solve your issues with image make this common method to use in multiple views…

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

Sidebar

Related Questions

I'm developing an Android app where the user is allowed to rest his hand
In my app,user can select image from gallery and after that he can zoom
I'm developing web app that user can save his/her work to server. The data
I have a small php server side app where the user is allowed to
Essentially what I want is for the app, once the user has allowed access
I have a rails app, that when a user is logged into his account,
How to do this on Google App Engine (Python): SELECT COUNT(DISTINCT user) FROM event
In the app I'm currently working with the user is allowed to store a
I have completed my iOS app and now want to have user registration and
I'm trying to retrieve profile information regarding users who allowed my app to collect

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.