Swiftgram/submodules/AsyncDisplayKit/docs/_docs/debug-tool-pixel-scaling.md
Peter 9bc996374f Add 'submodules/AsyncDisplayKit/' from commit '02bedc12816e251ad71777f9d2578329b6d2bef6'
git-subtree-dir: submodules/AsyncDisplayKit
git-subtree-mainline: d06f423e0ed3df1fed9bd10d79ee312a9179b632
git-subtree-split: 02bedc12816e251ad71777f9d2578329b6d2bef6
2019-06-11 18:42:43 +01:00

2.4 KiB
Executable File
Raw Blame History

title layout permalink prevPage nextPage
Image Scaling docs /docs/debug-tool-pixel-scaling.html debug-tool-hit-test-visualization.html debug-tool-ASRangeController.html

Visualize ASImageNode.images pixel scaling


This debug feature adds a red text overlay on the bottom right hand corner of an ASImageNode if (and only if) the images size in pixels does not match its bounds size in pixels, e.g.
SwiftObjective-C
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; }

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
}

This debug feature is useful for quickly determining if you are

  • downloading and rendering excessive amounts of image data
  • upscaling a low quality image

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 its 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.

screen shot 2016-03-25 at 4 04 59 pm

Usage


In your `AppDelegate.m` file,
  • import AsyncDisplayKit+Debug.h
  • add [ASImageNode setShouldShowImageScalingOverlay:YES] at the top of your AppDelegate's didFinishLaunchingWithOptions: method

Make sure to call this method before initializing any ASImageNodes.