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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:49:23+00:00 2026-06-17T18:49:23+00:00

I convert an image to NSData and NSData to base64string using NSData *imagedata =

  • 0

I convert an image to NSData and NSData to base64string using

NSData *imagedata = UIImageJPEGRepresentation(imageView.image, 0.1f);
NSString *c = [NSString base64StringFromData:imagedata];

the fn for stringconversion

+ (NSString*)base64forData:(NSData*)theData {

    const uint8_t* input = (const uint8_t*)[theData bytes];
    NSInteger length = [theData length];

    static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

    NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
    uint8_t* output = (uint8_t*)data.mutableBytes;

    NSInteger i;
    for (i=0; i < length; i += 3) {
        NSInteger value = 0;
        NSInteger j;
        for (j = i; j < (i + 3); j++) {
            value <<= 8;

            if (j < length) {
            value |= (0xFF & input[j]);
           }
        }

        NSInteger theIndex = (i / 3) * 4;
        output[theIndex + 0] =                    table[(value >> 18) & 0x3F];
        output[theIndex + 1] =                    table[(value >> 12) & 0x3F];
        output[theIndex + 2] = (i + 1) < length ? table[(value >> 6)  & 0x3F] : '=';
        output[theIndex + 3] = (i + 2) < length ? table[(value >> 0)  & 0x3F] : '=';
    }

    return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
}

but the resulted base64string is too long, its length is above 300000.
ie,

int len = c.length;

value of len is above 300000.

the image is of 3 to 4 mb
infact I compress the image to 0.1f

 NSData *imagedata = UIImageJPEGRepresentation(iivv.image, 0.1f);

how to minimize the length, is there any other code for base64conversion from NSData?

  • 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-17T18:49:25+00:00Added an answer on June 17, 2026 at 6:49 pm

    Base64 will always have larger space requirements than the original data, because it does not use all the bits in one byte. This is done intentionally in order to make sure that higher bits do not cause problems when being handed from one system to another. So in effect it trades space for transmission safety.

    It is called Base64 because it only uses 6 bits (2^6=64) for each byte, therefore effectively taking up 5 bytes where the original data only had 4. Or put another way: size will increase by 25%.

    The Base64 encoder of course does not care about what the bytes you feed into it represent, so you are free to compress the heck out of your data, as long as it is still in its own format (e. g. create a PNG or JPG out of uncompressed image data) and then encode that as Base64.

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

Sidebar

Related Questions

Anyone knows how to convert .jpg image to .bmp format in iphone using objective-C?
Using foundation and cocoa frameworks on Mac, I am trying to convert an NSData
NSData *imageData = UIImagePNGRepresentation(your_image_here); After that i transferred it to another iPhone using bluetooth.
How to convert imagedata into base64 my code is: UIImage *image = [UIImage imageNamed:@BombTense.png];
I want to convert image to grayscale on canvas by using Kinetic.js. So I
I need to convert image sequences(ie,png) to video file in iPhone. How i can
I have searched on the web for software that batch convert image at different
i convert an image to base64 string to upload through HttpWebRequest in c#.on server
I need to convert a image to base64binary content. Can we do it in
how can i convert eps image to jpg/png. any good application you can suggest.

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.