• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scaling a UIImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scaling a UIImage


  • Subject: Re: Scaling a UIImage
  • From: Alex Zavatone via Cocoa-dev <email@hidden>
  • Date: Mon, 2 Nov 2020 22:56:26 -0600

I’lll dig up a utility class that I made for UIImage that has this as well as
others.

Cheers.

> On Nov 2, 2020, at 4:59 PM, Carl Hoefs via Cocoa-dev
> <email@hidden> wrote:
>
> How can I correctly scale a UIImage from 3264x2448 down to 640x480 pixels?
>
>
> I have an iOS app that interacts with a macOS server process. The iOS app
> takes a 3264x2448 camera image, scales it to 640x480 pixels, and makes a JPEG
> representation of it to send to the server:
>
>  NSData *dataObj = UIImageJPEGRepresentation(origImage,0.5);
>
> The server reads the bytes, and creates an NSImage:
>
>  NSImage *theImage = [[NSImage alloc] initWithData:imageData];
>  NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc]
> initWithData:[theImage TIFFRepresentation]];
>
> But at this point, imageRep.pixelsWide=1280 and imageRep.pixelsHigh=960!
>
> If I write theImage to disk and look at it with Preview, it displays onscreen
> as 640x480 but Preview's Inspector Tool shows it to be 1280x960.
>
> On the iOS app side, here's the UIImage category method I'm using to scale
> the image:
>
> + (UIImage *)imageWithImage:(UIImage *)image
>               scaledToSize:(CGSize)newSize
> {
>    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
>    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
>    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
>    UIGraphicsEndImageContext();
>    return newImage;
> }
>
> Any suggestions?
> -Carl
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Scaling a UIImage (From: Carl Hoefs via Cocoa-dev <email@hidden>)

  • Prev by Date: Re: Scaling a UIImage
  • Next by Date: Re: Scaling a UIImage
  • Previous by thread: Re: Scaling a UIImage
  • Next by thread: Re: Scaling a UIImage
  • Index(es):
    • Date
    • Thread