API Cleanup: Use PixelSize for device-dependent sizes. #1889
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is something I've been meaning to do for years... Our API was inconsistent about accepting pixel sizes and DPI. For example:
RenderTargetBitmap
accepted a DPI butWriteableBitmap
didn'tIBitmap
didn't expose the DPI so once it was put intoRenderTargetBitmap
it couldn't be read againVector
and sometimes by a pair ofdouble
sThis PR introduces a new
struct PixelSize
which has anint
width and height, and also methods for converting to/from aSize
with a specified DPI (instead of having to dosize = new Size(width / (dpi / 96, height / (dpi / 96));
which isn't so easy to remember). Hopefully this helps make the distinction between device-independent pixels and device pixels clearer.Wherever a pixel size is passed to a constructor to create a bitmap, a DPI is also passed as a
Vector
.Unfortunately Skia doesn't provide an API for getting an image's DPI, so images loaded there are always 96dpi. Not sure what to do about this. For this reason
Image
still always uses the pixel size as the size to render, rather than the pixel size scaled by DPI.