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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:09:18+00:00 2026-05-26T12:09:18+00:00

I want to do the same thing as asked in this question. In my

  • 0

I want to do the same thing as asked in this question.
In my App i want to crop the image like we do image cropping in FaceBook can any one guide me with the link of good tutorial or with any sample code. The Link which i have provided will completely describe my requirement.

  • 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-26T12:09:18+00:00Added an answer on May 26, 2026 at 12:09 pm

    You may create new image with any properties. Here is my function, witch do that. you just need to use your own parameters of new image. In my case, image is not cropped, I just making some effect, moving pixels from there original place to another. But if you initialize new image with another height and width, you can just copy from any range of pixels of old image you need, to new one:

    -(UIImage *)Color:(UIImage *)img
    {
        int R;
        float m_width = img.size.width;
        float m_height = img.size.height;
        if (m_width>m_height) R = m_height*0.9;
        else R = m_width*0.9;
        int m_wint = (int)m_width;      //later,  we will need this parameters in float and int. you may just use "(int)" and "(float)" before variables later, and do not implement another ones
        int m_hint = (int)m_height;
    
        CGRect imageRect;
        //cheking image orientation. we will work with image pixel-by-pixel, so we need to make top side at the top.
        if(img.imageOrientation==UIImageOrientationUp 
           || img.imageOrientation==UIImageOrientationDown) 
        {
            imageRect = CGRectMake(0, 0, m_wint, m_hint); 
        }
        else 
        {
            imageRect = CGRectMake(0, 0, m_hint, m_wint); 
        }
        uint32_t *rgbImage = (uint32_t *) malloc(m_wint * m_hint * sizeof(uint32_t));
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        CGContextRef context = CGBitmapContextCreate(rgbImage, m_wint, m_hint, 8, m_wint *sizeof(uint32_t), colorSpace,   kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
        CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
        CGContextSetShouldAntialias(context, NO);
        CGContextTranslateCTM(context, 0, m_hint);
        CGContextScaleCTM(context, 1.0, -1.0);
        switch (img.imageOrientation) {
            case UIImageOrientationRight:
            {
                CGContextRotateCTM(context, M_PI / 2);
                CGContextTranslateCTM(context, 0, -m_wint);            
            }break;
            case UIImageOrientationLeft:
            {
                CGContextRotateCTM(context, - M_PI / 2);
                CGContextTranslateCTM(context, -m_hint, 0);            
            }break;
            case UIImageOrientationUp:
            {
                CGContextTranslateCTM(context, m_wint, m_hint);
                CGContextRotateCTM(context, M_PI);
            }
            default:
                break;
        }
    
        CGContextDrawImage(context, imageRect, img.CGImage);
        CGContextRelease(context);
        CGColorSpaceRelease(colorSpace);
    
        //here is new image. you can change m_wint and m_hint as you whant
        uint8_t *result = (uint8_t *) calloc(m_wint * m_hint * sizeof(uint32_t), 1);
        for(int y = 0; y < m_hint; y++) //new m_hint here
        {
            float fy=y;
            double yy =    (m_height*(  asinf(m_height/(2*R))-asin(((m_height/2)-fy)/R)   )) /
            (2*asin(m_height/(2*R))); // (xx, yy) - coordinates of pixel of OLD image
            for(int x =  0; x < m_wint; x++) //new m_wint here
            {
                float fx=x;
                double xx =    (m_width*(  asin(m_width/(2*R))-asin(((m_width/2)-fx)/R)   )) /
                (2*asin(m_width/(2*R)));
                uint32_t rgbPixel=rgbImage[(int)yy * m_wint + (int)xx];
                int intRedSource = (rgbPixel>>24)&255;
                int intGreenSource = (rgbPixel>>16)&255;
                int intBlueSource = (rgbPixel>>8)&255;
                result[(y * (int)m_wint + x) * 4] = 0;
                result[(y * (int)m_wint + x) * 4 + 1] = intBlueSource;
                result[(y * (int)m_wint + x) * 4 + 2] = intGreenSource;
                result[(y * (int)m_wint + x) * 4 + 3] = intRedSource;
    
            }
        }
    
        free(rgbImage);
    
        colorSpace = CGColorSpaceCreateDeviceRGB();
        context = CGBitmapContextCreate(result, m_wint, m_hint, 8, m_wint * sizeof(uint32_t), colorSpace,   kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast  ); //new m_wint and m_hint as well
    
    
        CGImageRef image1 = CGBitmapContextCreateImage(context);
        CGContextRelease(context);
        CGColorSpaceRelease(colorSpace);
        UIImage *resultUIImage = [UIImage imageWithCGImage:image1];
        CGImageRelease(image1);
    
    
        @try {
            free(result);
        }
        @catch (NSException * e) {
            NSLog(@"proc. Exception: %@", e);
        }
    
        return resultUIImage;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I previously asked this question on the Facebook forums but apparently they want us
I have this Java code, and I want to do the same thing in
I guess this question has been asked a lot around. I know Rails can
My question is related to this one I asked on ServerFault . Based on
In a nutshell: I want to do the same thing Dependency Walker does. Is
I want these two print functions to do the same thing: unsigned int Arraye[]
Basically, I want to achieve the same thing as ON DUPLICATE KEY in MySQL.
For my C# RichTextBox, I want to programmatically do the same thing as clicking
i want something like this the user enter a website link i need check
i know this question has been asked here but i am stuck with this

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.