mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00

git-subtree-dir: submodules/AsyncDisplayKit git-subtree-mainline: d06f423e0ed3df1fed9bd10d79ee312a9179b632 git-subtree-split: 02bedc12816e251ad71777f9d2578329b6d2bef6
61 lines
2.4 KiB
Markdown
Executable File
61 lines
2.4 KiB
Markdown
Executable File
---
|
||
title: Image Scaling
|
||
layout: docs
|
||
permalink: /docs/debug-tool-pixel-scaling.html
|
||
prevPage: debug-tool-hit-test-visualization.html
|
||
nextPage: debug-tool-ASRangeController.html
|
||
---
|
||
|
||
## Visualize ASImageNode.image’s pixel scaling
|
||
<br>
|
||
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.
|
||
|
||
<div class = "highlight-group">
|
||
<span class="language-toggle"><a data-lang="swift" class="swiftButton">Swift</a><a data-lang="objective-c" class = "active objcButton">Objective-C</a></span>
|
||
|
||
<div class = "code">
|
||
<pre lang="objc" class="objcCode">
|
||
CGFloat imageSizeInPixels = image.size.width * image.size.height;
|
||
CGFloat boundsSizeInPixels = imageView.bounds.size.width * imageView.bounds.size.height;
|
||
CGFloat scaleFactor = imageSizeInPixels / boundsSizeInPixels;
|
||
|
||
if (scaleFactor != 1.0) {
|
||
NSString *scaleString = [NSString stringWithFormat:@"%.2fx", scaleFactor];
|
||
_debugLabelNode.hidden = NO;
|
||
}
|
||
</pre>
|
||
<pre lang="swift" class = "swiftCode hidden">
|
||
let imageSizeInPixels = image.size.width * image.size.height
|
||
let boundsSizeInPixels = imageView.bounds.size.width * imageView.bounds.size.height
|
||
let scaleFactor = imageSizeInPixels / boundsSizeInPixels
|
||
|
||
if scaleFactor != 1.0 {
|
||
let scaleString = "\(scaleFactor)"
|
||
_debugLabelNode.hidden = false
|
||
}
|
||
</pre>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<b>This debug feature is useful for quickly determining if you are</b>
|
||
|
||
<ul>
|
||
<li><b>downloading and rendering excessive amounts of image data</b></li>
|
||
<li><b>upscaling a low quality image</b></li>
|
||
</ul>
|
||
|
||
In the screenshot below of an app with this debug feature enabled, you can see that the avatar image is unnecessarily large (9x too large) for it’s bounds size and that the center picture is more optimized, but not perfectly so. If you control your own endpoint, make sure to return an optimally sized image.
|
||
|
||

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