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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:34:32+00:00 2026-06-16T01:34:32+00:00

I have the following category for resizing UIImage objects: // UIImage+TSResize.h #import <UIKit/UIKit.h> /**

  • 0

I have the following category for resizing UIImage objects:

// UIImage+TSResize.h

#import <UIKit/UIKit.h>

/**
    This is a UIImage category that allows for the resizing of UIImages. The code for the main function (imageWithImage:scaledToFillSize:withScaleFactor: was obtained at: http://stackoverflow.com/questions/2658738/the-simplest-way-to-resize-an-uiimage
 */
@interface UIImage (TSResize)

/**
    Returns a resized UIImage that will fill the area provided.
    @param image The image to resize.
    @param size The size for the new image.
    @param scaleFactor The scale factor to apply to the image. This is 2.0 for retina display device. If 0.0 is specfied, it will select the scale factor for the current device.
    @returns The resized image.
 */
+ (UIImage *)imageWithImage:(UIImage *)image scaleToFillSize:(CGSize)size withScaleFactor:(CGFloat)scaleFactor;

/**
    Returns a aspect resized UIImage that will fit within the size provided.
    @param image The image to resize.
    @param size The size that the new image should fit within.
    @param scaleFactor The scale factor to apply to the image. This is 2.0 for retina display device. If 0.0 is specfied, it will select the scale factor for the current device.
    @returns The resized image.
 */
+ (UIImage *)imageWithImage:(UIImage *)image scaleAspectFitSize:(CGSize)size withScaleFactor:(CGFloat)scaleFactor;

/**
    Returns a aspect resized UIImage that will fill size provided. This image has not been cropped to remain within the size provided if the aspect ratios are different.
    @param image The image to resize.
    @param size The size that the image should fill.
    @param scaleFactor The scale factor to apply to the image. This is 2.0 for retina display device. If 0.0 is specfied, it will select the scale factor for the current device.
    @returns The resized image.
 */
+ (UIImage *)imageWithImage:(UIImage *)image scaleToAspectFillSizeWithoutCropping:(CGSize)size withScaleFactor:(CGFloat)scaleFactor;

@end

&

// UIImage+Resize.m

#import "UIImage+TSResize.h"

@implementation UIImage (TSResize)

+ (UIImage *)imageWithImage:(UIImage *)image scaleToFillSize:(CGSize)size withScaleFactor:(CGFloat)scaleFactor {
    UIGraphicsBeginImageContextWithOptions(size, NO, scaleFactor);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

+ (UIImage *)imageWithImage:(UIImage *)image scaleAspectFitSize:(CGSize)size withScaleFactor:(CGFloat)scaleFactor {
    // Find the smallest scaling factor of the two sides.
    CGFloat scalingFactor = 0.0;

    CGFloat heightScalingFactor = size.height / image.size.height;
    CGFloat widthScalingFactor = size.width / image.size.width;

    if (heightScalingFactor < widthScalingFactor) {
        scalingFactor = heightScalingFactor;
    } else {
        scalingFactor = widthScalingFactor;
    }

    CGSize scaledSize;

    scaledSize.height = image.size.height * scalingFactor;
    scaledSize.width = image.size.width * scalingFactor;

    return [self imageWithImage:image scaleToFillSize:scaledSize withScaleFactor:scaleFactor];
}

+ (UIImage *)imageWithImage:(UIImage *)image scaleToAspectFillSizeWithoutCropping:(CGSize)size withScaleFactor:(CGFloat)scaleFactor {
    // Find the largest scaling factor of the two sides.
    CGFloat scalingFactor = 0.0;

    CGFloat heightScalingFactor = size.height / image.size.height;
    CGFloat widthScalingFactor = size.width / image.size.width;

    if (heightScalingFactor > widthScalingFactor) {
        scalingFactor = heightScalingFactor;
    } else {
        scalingFactor = widthScalingFactor;
    }

    CGSize scaledSize;

    scaledSize.height = image.size.height * scalingFactor;
    scaledSize.width = image.size.width * scalingFactor;

    return [self imageWithImage:image scaleToFillSize:scaledSize withScaleFactor:scaleFactor];
}

@end

What I want to know is if its safe to use these functions in a thread other then the main thread.

  • 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-16T01:34:33+00:00Added an answer on June 16, 2026 at 1:34 am

    Yes these functions are thread-safe.

    Documentation

    In iOS 4 and later, you may call this function from any thread of your app.

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

Sidebar

Related Questions

I have following code in a html form <select name=category class=input onchange=ShowTB(this,'suggest');> <option value=0
I have the following code: $(document).ready(function() { // Manage sidebar category display jQuery(#categories >
I have the following category: @interface UIViewController (Additions) - (void)exampleMethod; @end ----- #import UIViewController+Additions.h
I have use following code to display category and there product on click patent
Let's say that I have the following string Type=Category Position=Top Child=3 ABC=XYZ.... And 2
I have following receiver that listens to Boot_Completed <receiver android:name=.receivers.ActionBootCompletedReceiver> <intent-filter> <action android:name=android.intent.action.BOOT_COMPLETED/> <category
I have the following two tables that record expenditure and provide expenditure category information:
I have following code: mQuestions=DictionaryDbWrapper.getInstance().getQuestionsSequence( this.getIntent().getStringExtra(ApplicationUtilities.TEST_CATEGORY_PARAMETER), 50); mQuestionsCount=mQuestions.size(); Log.e(count, String.valueOf(mQuestionsCount)); if (mQuestionsCount==0) { Log.e(1,
I have the following tables category, Restaurant, and menu. A restaurant can have more
I have following Table with records for ActivityLog: ID, UserId, Category, Created 1 11

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.