mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-20 07:05:36 +08:00
32 lines
1.7 KiB
Markdown
32 lines
1.7 KiB
Markdown
---
|
||
title: Image Scaling
|
||
layout: docs
|
||
permalink: /docs/debug-tool-pixel-scaling.html
|
||
next: debug-tool-hit-test-slop.html
|
||
---
|
||
|
||
##Visualize ASImageNode.image’s pixel scaling##
|
||
This debug feature adds a red text overlay on the bottom right hand corner of an ASImageNode if (and only if) the image’s size in pixels does not match it’s bounds size in pixels, e.g.
|
||
|
||
```objective-c
|
||
imageSizeInPixels = image.size * image.scale
|
||
boundsSizeInPixels = bounds.size * contentsScale
|
||
scaleFactor = imageSizeInPixels / boundsSizeInPixels
|
||
|
||
if (scaleFactor != 1.0) {
|
||
NSString *scaleString = [NSString stringWithFormat:@"%.2fx", scaleFactor];
|
||
_debugLabelNode.hidden = NO;
|
||
}
|
||
```
|
||
|
||
This debug feature is useful for **quickly determining if you are (1) downloading and rendering excessive amounts of image data or (2) upscaling a low quality image**. In the screenshot below, you can quickly see that the avatar image is unnecessarily large for it’s bounds size and that the center picture is more optimized, but not perfectly so. If you are using an external data source (such as the 500px API used in the example), it's likely that you won’t be able to get the scaleFactor to exactly 1.0. However, if you control your own endpoint, optimize your API / app to return a correctly sized image!
|
||
|
||

|
||
### Usage
|
||
In your `AppDelegate.m` file,
|
||
<ul>
|
||
<li>import `AsyncDisplayKit+Debug.h`</li>
|
||
<li>add `[ASImageNode setShouldShowImageScalingOverlay:YES];` at the top of `didFinishLaunchingWithOptions:` </li>
|
||
</ul>
|
||
Make sure to call this method before initializing any ASImageNodes.
|