Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
UIImage: Difference between revisions - iPhone Development Wiki

UIImage: Difference between revisions

From iPhone Development Wiki
(Created page with '{{occlass|library=UIKit.framework}} UIImage is an Objective-C class that represents a bitmap image. == Undocumented methods == === -_applicationIconImagePrecomposed: & -_s…')
 
No edit summary
 
(21 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{occlass|library=UIKit.framework}}
[[UIImage]] is an Objective-C class that represents a bitmap image.  
[[UIImage]] is an Objective-C class that represents a bitmap image.  


== Undocumented methods ==
== Undocumented methods ==
=== -_applicationIconImagePrecomposed: & -_smallApplicationIconImagePrecomposed: ===
=== Precomposed icon ===
[[Image:AppIcon.png|right|framed|From left to right: The original image; <tt>_applicationIconImagePrecomposed:NO</tt>; <tt>_applicationIconImagePrecomposed:YES</tt>; <tt>_smallApplicationIconImagePrecomposed:NO</tt>; <tt>_smallApplicationIconImagePrecomposed:YES</tt>]]
[[Image:AppIcon.png|right|framed|From left to right: The original image; <tt>_applicationIconImagePrecomposed:NO</tt>; <tt>_applicationIconImagePrecomposed:YES</tt>; <tt>_smallApplicationIconImagePrecomposed:NO</tt>; <tt>_smallApplicationIconImagePrecomposed:YES</tt>]]


{{Function signature|signature=-(UIImage*)_applicationIconImagePrecomposed:(BOOL)precomposed;|firmware=2.0 – 3.1}}
{{Function signature|signature=-(UIImage*)_applicationIconImageForFormat:(int)format precomposed:(BOOL)precomposed scale:(CGFloat)scale;|firmware=4.0 –}}
{{Function signature|signature=-(UIImage*)_applicationIconImageForFormat:(int)format precomposed:(BOOL)precomposed;|firmware=3.2 –}}
{{Function signature|signature=-(UIImage*)_applicationIconImagePrecomposed:(BOOL)precomposed;|firmware=2.0 – 4.0}}
{{Function signature|signature=-(UIImage*)_smallApplicationIconImagePrecomposed:(BOOL)precomposed;|firmware=2.0 – 3.1}}
{{Function signature|signature=-(UIImage*)_smallApplicationIconImagePrecomposed:(BOOL)precomposed;|firmware=2.0 – 3.1}}


These methods resize an image to icon size (59&times;59) or small icon size (29&times;29), clip out a rounded rectangle, draw shadows and apply a glossy overlay if required (when <tt>precomposed == NO</tt>), so that it resembles an icon.
These methods resize an image to the size of a particular style of iOS icon. Depending on the <tt>format</tt> provided, they may also clip out a rounded rectangle or add other effects. Pre-iOS 7, these methods drew shadows and applied a glossy overlay when <tt>precomposed == NO</tt>.
 
{| class="wikitable"
|-
! rowspan="2" | Format
! colspan="2" | Size
! colspan="3" | MobileIcons variant
! rowspan="2" | Description
|-
! iPhone !! iPad
! iPhone !! iPad 2x !! iPad 1x
|-
| 0 || 29&times;29 || 29&times;29 || 4 || 17 || 4 ||
|-
| 1 || 29&times;29 || 50&times;50 || 2 || 16 || 3 || the small icon that appears in Spotlight
|-
| 2 || 59&times;62 || 74&times;78 || 0 || 15 || 1 || the large icon that appears in home screen (default)
|-
| 3 || 44&times;45 || 74&times;78 || 22 || 23 || 1 || for use in GameCenter (?)
|-
| 4 || 59&times;62 || 74&times;78 || 24 || 25 || 26 || in gray scale
|-
| 5 || 31&times;37 || 64&times;64 || 18 || 19 || 5 || document-like picture filled with the specified image
|-
| 6 || 31&times;37 || 64&times;64 || 20 || 21 || 7 || document-like picture with a small icon
|}
 
The rendering of icon is actually done by {{fwlink|MobileIcons}}.


If the input image is rectangular, the largest square portion in the top-left corner will be used.
If the input image is rectangular, the largest square portion in the top-left corner will be used.
Example:<source lang="objc">
@interface UIImage (privateAPI)
-(UIImage*)_applicationIconImagePrecomposed:(BOOL)precomposed;
@end
...
UIImage *regularIcon = [UIImage imageNamed:@"regularIcon.png"];
UIImage *renderedIcon = [regularIcon _applicationIconImageForFormat:2 precomposed:NO];
NSData  *pngData = UIImagePNGRepresentation( renderedIcon );
[pngData writeToFile:@"/tmp/roundedIcon.png" atomically:YES];
</source>


=== _flatImageWithWhite:alpha: ===
=== _flatImageWithWhite:alpha: ===
{{Function signature|signature=-(UIImage*)_flatImageWithWhite:(CGFloat)white alpha:(CGFloat)alpha;|firmware=2.0 – 3.1}}
{{Function signature|signature=-(UIImage*)_flatImageWithWhite:(CGFloat)white alpha:(CGFloat)alpha;|firmware=2.0 –}}


Create an image having the same size as the original image, but filled with the solid color as the parameters.
Create an image having the same size as the original image, but filled with the solid color as the parameters.
Line 25: Line 63:


=== _imageScaledToSize:interpolationQuality: & _imageScaledToProportion:interpolationQuality: ===
=== _imageScaledToSize:interpolationQuality: & _imageScaledToProportion:interpolationQuality: ===
{{Function signature|signature=-(UIImage*)_imageScaledToSize:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality;|firmware=2.0 – 3.1}}
{{Function signature|signature=-(UIImage*)_imageScaledToSize:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality;|firmware=2.0 – 3.2}}
{{Function signature|signature=-(UIImage*)_imageScaledToProportion:(CGFloat)scale interpolationQuality:(CGInterpolationQuality)quality;|firmware=2.0 – 3.1}}
{{Function signature|signature=-(UIImage*)_imageScaledToProportion:(CGFloat)scale interpolationQuality:(CGInterpolationQuality)quality;|firmware=2.0 –}}


Rescale the image to the new size.
Rescale the image to the new size.
=== _flatImageWithColor: ===
{{Function signature|signature=-(UIImage *)_flatImageWithColor:(UIColor *)color;|firmware=7.0 –}}
Replace the color of the UIImage with the given color.


=== +kitImageNamed: ===
=== +kitImageNamed: ===
{{Function signature|signature=+(UIImage*)kitImageNamed:(NSString*)name;|firmware=2.0 – 3.1}}
{{Function signature|signature=+(UIImage*)kitImageNamed:(NSString*)name;|firmware=2.0 –}}


Equivalent to <tt>_UIImageWithName(name)</tt>.
Equivalent to <tt>_UIImageWithName(name)</tt>.


=== +defaultDesktopImage ===
=== +defaultDesktopImage ===
{{Function signature|signature=+(UIImage*)defaultDesktopImage;|firmware=2.0 – 3.1}}
{{Function signature|signature=+(UIImage*)defaultDesktopImage;|firmware=2.0 – 4.1}}


Return the user's lock screen image.
Return the user's lock screen image.


=== +setDesktopImageData: ===
=== +setDesktopImageData: ===
{{Function signature|signature=+(void)setDesktopImageData:(NSData*)jpegData;|firmware=2.0 – 3.1}}
{{Function signature|signature=+(void)setDesktopImageData:(NSData*)jpegData;|firmware=2.0 – 3.2}}
{{Function signature|signature=+(void)setDesktopImageData:(NSData*)data composedPortraitImageData:(NSData*)data2 composedLandscapeImageData:(NSData*)data3 forVariant:(int)variant;|firmware=4.0 – 4.1}}


Replace the user's lock screen image by the given JPEG data.
Replace the user's lock screen image by the given JPEG data.
=== +_deviceSpecificImageNamed: (inBundle:) ===
{{Function signature|signature=+(UIImage *)_deviceSpecificImageNamed:(NSString *)name;}}
{{Function signature|signature=+(UIImage *)_deviceSpecificImageNamed:(NSString *)name inBundle:(NSBundle *)bundle;}}
Like +imageNamed:(inBundle:) but with support for special longphone images (-568h)
=== +_pu_PhotosUIImageNamed: ===
{{Function signature|signature=+(UIImage *)_pu_PhotosUIImageNamed:(NSString *)name;|firmware=7.0 –}}
Return the UIImage in PhotosUI.framework by the given image name.


== Undocumented C functions ==
== Undocumented C functions ==
=== _UIImageWithName ===
=== _UIImageWithName ===
{{Function signature|signature=UIImage* _UIImageWithName(NSString* name);|firmware=2.0 – 3.1}}
{{Function signature|signature=UIImage* _UIImageWithName(NSString* name);|firmware=2.0 –}}


Obtain a built-in image. The name are stored in <tt>UIKit.framework/*.artwork</tt>. There are various ways to extract this information<ref>iPhoneShop http://code.google.com/p/iphoneshop/ – may not work on 3.x</ref><ref>http://svn.saurik.com/repos/menes/trunk/winterboard/UIImages.mm</ref><ref>http://code.google.com/p/networkpx/source/browse/etc/dump-artwork.m – Tested only on 3.x</ref>, and you can grab a (slightly outdated) list from http://test.saurik.com/winterboard/UIImages.txt.
Obtain a built-in image. The name are stored in <tt>UIKit.framework/*.artwork</tt>. There are various ways to extract this information<ref>iPhoneShop http://code.google.com/p/iphoneshop/ – may not work on 3.x</ref><ref>https://github.com/davepeck/iphone-tidbits</ref>. A list of image names may also be helpful: [http://pastie.org/6508614 6.0], [http://test.saurik.com/winterboard/UIImages.txt 2.0].


=== UIImageDataWriteToSavedPhotosAlbum ===
=== UIImageDataWriteToSavedPhotosAlbum ===
{{Function signature|signature=void UIImageDataWriteToSavedPhotosAlbum(NSData* imageData, id target, SEL selector, void* context);|firmware=3.1}}
{{Function signature|signature=void UIImageDataWriteToSavedPhotosAlbum(NSData* imageData, id target, SEL selector, void* context);|firmware=3.1 }}


Write the image data to photos album. This is similar to [http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/doc/uid/TP40006894-CH3-SW29 UIImageWriteToSavedPhotosAlbum] function in the SDK, except that you can choose the image format (the extension will always be *.jpg, however).
Write the image data to photos album. This is similar to [http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/doc/uid/TP40006894-CH3-SW29 UIImageWriteToSavedPhotosAlbum] function in the SDK, except that you can choose the image format (the extension will always be *.jpg, however).
=== UIGetScreenImage ===
{{function signature|signature=CGImageRef UIGetScreenImage();|firmware=2.0 –}}
{{function signature|signature=CGImageRef UICreateScreenImage();|firmware=3.2 –}}
"Print screen" and returns the image. Note that this is a CGImage, so you need to convert it to a UIImage with {{ObjcCall|UIImage|imageWithCGImage:|ClassMethod=1}}.
Note that, although being a "Get" function, the returned image actually has retain count of +1, and the caller (you) are responsible to CGImageRelease it.
This function can be used for SDK apps between 2009 December<ref>http://www.steveperks.co.uk/post/Apple-Allows-UIGetScreenImage-For-iPhone.aspx</ref> and 2010 July<ref>http://www.tuaw.com/2010/07/21/devsugar-rip-uigetscreenimage/</ref>
In firmware 3.2, <tt>UIGetScreenImage</tt> becomes an alias of the more appropriately-named <tt>UICreateScreenImage</tt>.
In arm64 version of iOS 7, the UIGetScreenImage was removed.
=== _UICreateScreenUIImage ===
{{function signature|signature=UIImage* _UICreateScreenUIImage();|firmware=? –}}
Returns an image containing the contents of the screen. While similar in function to <tt>UIGetScreenImage</tt>, it uses the much faster <tt>CARenderServerRenderDisplay</tt> to perform the capture.


== References ==
== References ==
Line 60: Line 132:
* Official documentation: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImage_Class/Reference/Reference.html
* Official documentation: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImage_Class/Reference/Reference.html
* Extra header: http://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIImage2.h
* Extra header: http://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIImage2.h
{{occlass|library=UIKit.framework|navbox=on}}

Latest revision as of 05:41, 8 November 2014

UIImage is an Objective-C class that represents a bitmap image.

Undocumented methods

Precomposed icon

From left to right: The original image; _applicationIconImagePrecomposed:NO; _applicationIconImagePrecomposed:YES; _smallApplicationIconImagePrecomposed:NO; _smallApplicationIconImagePrecomposed:YES
Signature -(UIImage*)_applicationIconImageForFormat:(int)format precomposed:(BOOL)precomposed scale:(CGFloat)scale;
Available in 4.0 –
Signature -(UIImage*)_applicationIconImageForFormat:(int)format precomposed:(BOOL)precomposed;
Available in 3.2 –
Signature -(UIImage*)_applicationIconImagePrecomposed:(BOOL)precomposed;
Available in 2.0 – 4.0
Signature -(UIImage*)_smallApplicationIconImagePrecomposed:(BOOL)precomposed;
Available in 2.0 – 3.1

These methods resize an image to the size of a particular style of iOS icon. Depending on the format provided, they may also clip out a rounded rectangle or add other effects. Pre-iOS 7, these methods drew shadows and applied a glossy overlay when precomposed == NO.

Format Size MobileIcons variant Description
iPhone iPad iPhone iPad 2x iPad 1x
0 29×29 29×29 4 17 4
1 29×29 50×50 2 16 3 the small icon that appears in Spotlight
2 59×62 74×78 0 15 1 the large icon that appears in home screen (default)
3 44×45 74×78 22 23 1 for use in GameCenter (?)
4 59×62 74×78 24 25 26 in gray scale
5 31×37 64×64 18 19 5 document-like picture filled with the specified image
6 31×37 64×64 20 21 7 document-like picture with a small icon

The rendering of icon is actually done by MobileIcons.

If the input image is rectangular, the largest square portion in the top-left corner will be used.

Example:

@interface UIImage (privateAPI)
-(UIImage*)_applicationIconImagePrecomposed:(BOOL)precomposed;
@end
...
UIImage *regularIcon = [UIImage imageNamed:@"regularIcon.png"];
UIImage *renderedIcon = [regularIcon _applicationIconImageForFormat:2 precomposed:NO];
NSData  *pngData = UIImagePNGRepresentation( renderedIcon );
[pngData writeToFile:@"/tmp/roundedIcon.png" atomically:YES];

_flatImageWithWhite:alpha:

Signature -(UIImage*)_flatImageWithWhite:(CGFloat)white alpha:(CGFloat)alpha;
Available in 2.0 –

Create an image having the same size as the original image, but filled with the solid color as the parameters.

_bezeledImageWithRed:green:blue:alpha:

Signature -(UIImage*) _bezeledImageWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
Available in 2.0 – 3.1

Create a solid white image having the same size as the original image, and then stroke the top 1px edge by the specified color.

_imageScaledToSize:interpolationQuality: & _imageScaledToProportion:interpolationQuality:

Signature -(UIImage*)_imageScaledToSize:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality;
Available in 2.0 – 3.2
Signature -(UIImage*)_imageScaledToProportion:(CGFloat)scale interpolationQuality:(CGInterpolationQuality)quality;
Available in 2.0 –

Rescale the image to the new size.

_flatImageWithColor:

Signature -(UIImage *)_flatImageWithColor:(UIColor *)color;
Available in 7.0 –

Replace the color of the UIImage with the given color.

+kitImageNamed:

Signature +(UIImage*)kitImageNamed:(NSString*)name;
Available in 2.0 –

Equivalent to _UIImageWithName(name).

+defaultDesktopImage

Signature +(UIImage*)defaultDesktopImage;
Available in 2.0 – 4.1

Return the user's lock screen image.

+setDesktopImageData:

Signature +(void)setDesktopImageData:(NSData*)jpegData;
Available in 2.0 – 3.2
Signature +(void)setDesktopImageData:(NSData*)data composedPortraitImageData:(NSData*)data2 composedLandscapeImageData:(NSData*)data3 forVariant:(int)variant;
Available in 4.0 – 4.1

Replace the user's lock screen image by the given JPEG data.

+_deviceSpecificImageNamed: (inBundle:)

Signature +(UIImage *)_deviceSpecificImageNamed:(NSString *)name;
Signature +(UIImage *)_deviceSpecificImageNamed:(NSString *)name inBundle:(NSBundle *)bundle;

Like +imageNamed:(inBundle:) but with support for special longphone images (-568h)

+_pu_PhotosUIImageNamed:

Signature +(UIImage *)_pu_PhotosUIImageNamed:(NSString *)name;
Available in 7.0 –

Return the UIImage in PhotosUI.framework by the given image name.

Undocumented C functions

_UIImageWithName

Signature UIImage* _UIImageWithName(NSString* name);
Available in 2.0 –

Obtain a built-in image. The name are stored in UIKit.framework/*.artwork. There are various ways to extract this information[1][2]. A list of image names may also be helpful: 6.0, 2.0.

UIImageDataWriteToSavedPhotosAlbum

Signature void UIImageDataWriteToSavedPhotosAlbum(NSData* imageData, id target, SEL selector, void* context);
Available in 3.1 –

Write the image data to photos album. This is similar to UIImageWriteToSavedPhotosAlbum function in the SDK, except that you can choose the image format (the extension will always be *.jpg, however).

UIGetScreenImage

Signature CGImageRef UIGetScreenImage();
Available in 2.0 –
Signature CGImageRef UICreateScreenImage();
Available in 3.2 –

"Print screen" and returns the image. Note that this is a CGImage, so you need to convert it to a UIImage with +[UIImage imageWithCGImage:].

Note that, although being a "Get" function, the returned image actually has retain count of +1, and the caller (you) are responsible to CGImageRelease it.

This function can be used for SDK apps between 2009 December[3] and 2010 July[4]

In firmware 3.2, UIGetScreenImage becomes an alias of the more appropriately-named UICreateScreenImage.

In arm64 version of iOS 7, the UIGetScreenImage was removed.

_UICreateScreenUIImage

Signature UIImage* _UICreateScreenUIImage();
Available in ? –

Returns an image containing the contents of the screen. While similar in function to UIGetScreenImage, it uses the much faster CARenderServerRenderDisplay to perform the capture.

References