How to Easily Resize/Optimize an Image Size With Ios

How to easily resize/optimize an image size with iOS?

A couple of suggestions are provided as answers to this question. I had suggested the technique described in this post, with the relevant code:

+ (UIImage*)imageWithImage:(UIImage*)image 
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return newImage;
}

As far as storage of the image, the fastest image format to use with the iPhone is PNG, because it has optimizations for that format. However, if you want to store these images as JPEGs, you can take your UIImage and do the following:

NSData *dataForJPEGFile = UIImageJPEGRepresentation(theImage, 0.6);

This creates an NSData instance containing the raw bytes for a JPEG image at a 60% quality setting. The contents of that NSData instance can then be written to disk or cached in memory.

Image optimization in iOS after reducing of size via CATransform3D?

The most appropriate solution I found out is the following.

The unoptimized view is of the screen size and all the other transforms including scale are applied via CATransform3D.

To optimize I reduce the frame of the UIView, all of its subviews and even image manually (because in my case its placement mode in UIImageView doesn't meet any standard one). I still use the same complex CATransform3D but without scaling transform.

In both cases the initial anchor point (views' center) is the center of the screen.

To optimize the image I reduce its size immediately for current view and use cached ones for other views. If there is no cached image I try to recreate it.

compress image size without losing quality before uploading to server in iPhone

While going through Stackoverdflow following this link I find out following code

 + (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return newImage;
}

Resize Image based on resolution

How about [[UIScreen mainScreen] scale]?

Image sizes for display in an app - trying to reduce the size of images

You can edit images both programmatically and using other applications. If you optimize the images by code you will anyhow have to store it in the app thus increasing the size of the application so it is better to optimize and then add it to the project.

As easy to use website to optimize images is https://tinypng.com/

The simplest way to resize an UIImage?

The simplest way is to set the frame of your UIImageView and set the contentMode to one of the resizing options.

Or you can use this utility method, if you actually need to resize an image:

+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}

Example usage:

#import "MYUtil.h"

UIImage *myIcon = [MYUtil imageWithImage:myUIImageInstance scaledToSize:CGSizeMake(20, 20)];

Using ImageMagick, how can I resize an image to have minimum height or width, which ever is reached first

Using the comment before i arrived at

magick.exe in.png -resize "%[fx:min(w,h)<=1000 ? w : ( w>h ? (w/h*1000) : 1000) ]" out.png

Give it a shot and tell me if it works for all your usecases



Related Topics



Leave a reply



Submit