Issue 12519 in skia: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image

956 views
Skip to first unread message

patri… via monorail

unread,
Oct 11, 2021, 3:52:48 AM10/11/21
to bu...@skia.org
Status: Untriaged
Owner: ----
Priority: Medium
Type: Feature

New issue 12519 by patri...@gmail.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519

Hi,

In .NET6 Microsoft drop the support for System.Drawing.Common on non-Windows platform. It will be release in November). They advice to migrate to SkiaSharp (an of cource Skia as native dependency).
But a basic image manipulation feature is missing in Skia, the Get/Set of the image DPI.

Can you add this in Skia? Then the SkiaSharp team will add it in the wrapper ( https://github.com/mono/SkiaSharp/issues/804 )
Thanks

Patrick

--
You received this message because:
1. The project was configured to send all issue notifications to this address

You may adjust your notification preferences at:
https://bugs.chromium.org/hosting/settings

jvanv… via monorail

unread,
Oct 15, 2021, 2:36:53 PM10/15/21
to bu...@skia.org
Updates:
Owner: bsalo...@google.com

Comment #1 on issue 12519 by jvan...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c1

(No comment was entered for this change.)

bsalo… via monorail

unread,
Oct 15, 2021, 3:00:59 PM10/15/21
to bu...@skia.org

Comment #2 on issue 12519 by bsalo...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c2

Can you explain more about how this feature would work? Would it automatically apply a scale factor when drawing the image based on the image DPI?

patri… via monorail

unread,
Oct 18, 2021, 4:14:54 AM10/18/21
to bu...@skia.org

Comment #3 on issue 12519 by patri...@gmail.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c3

the Horizontal and Vertical resolutions are important when you scan, print or need to transform coordinates in an image.
Some examples :
You rasterize a pdf at 300 dpi into a jpg, the coordinates of the objects in a pdf are in 72dpi, so you need the image resolution to put annotations or other added objects at the right place.
You scan an image to 600 dpi, then you want to print it at the original dimension.

Clues for implementation :
BMP : In the bitmap header, you have PelsPerMeterX and PelsPerMeterY
Png : LibPng have png_set_pHYs png_get_pHYs
Jpg : LibJpeg jpeg_compress_struct Y_density X_density density_unit
Tiff : libTiff tag TIFFTAG_XRESOLUTION TIFFTAG_YRESOLUTION TIFFTAG_RESOLUTIONUNIT

micha… via monorail

unread,
Oct 18, 2021, 11:34:19 AM10/18/21
to bu...@skia.org
Updates:
Cc: scro...@google.com

Comment #4 on issue 12519 by michae...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c4

If I interpret the comments from the Xamarin forum post and the github issue, this is about storing the DPI when Skia encodes a PNG on output, so that some other layer (e.g. windows UI) knows how to interpret the image resolution correctly. CCing Leon if this is something we want to support, or if our encoders are meant to be basic and advanced encoding should use a dedicated PNG library?

jcgre… via monorail

unread,
Oct 18, 2021, 12:15:43 PM10/18/21
to bu...@skia.org
Updates:
Status: Unconfirmed

Comment #5 on issue 12519 by jcgre...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c5


(No comment was entered for this change.)

bsalo… via monorail

unread,
Oct 18, 2021, 12:22:59 PM10/18/21
to bu...@skia.org

Comment #6 on issue 12519 by bsalo...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c6

Thanks for that clarification, Michael.

patri… via monorail

unread,
Oct 18, 2021, 3:01:43 PM10/18/21
to bu...@skia.org

Comment #7 on issue 12519 by patri...@gmail.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c7

DPI are useful for every image format, not only PNG.
libpng, libjpeg, libtiff have this feature (read & write)

scro… via monorail

unread,
Oct 18, 2021, 3:08:28 PM10/18/21
to bu...@skia.org

Comment #8 on issue 12519 by scro...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c8

I think that would depend on the demand for the feature. We currently support a limited set of Options for PNG encodes [1], including comments, which were needed for Chromium. Given that precedent, and the fact that it would technically easy to add, it's somewhat reasonable, but I don't see it as high priority at the moment.

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/include/encode/SkPngEncoder.h;l=30?q=skpngencoder.h&ss=chromium

scro… via monorail

unread,
Oct 18, 2021, 3:09:46 PM10/18/21
to bu...@skia.org

Comment #9 on issue 12519 by scro...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c9

That's just for writing - I would say that reading it is out of scope for our decoders.

bsalo… via monorail

unread,
Oct 18, 2021, 3:18:19 PM10/18/21
to bu...@skia.org

Comment #10 on issue 12519 by bsalo...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c10

Right, incorporating DPI into how we render source images is a major API change and something we don't have bandwidth for. It's also possible to do this at a layer above Skia using scale matrices.

patri… via monorail

unread,
Oct 19, 2021, 3:25:53 AM10/19/21
to bu...@skia.org

Comment #11 on issue 12519 by patri...@gmail.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c11

You don't need dpi to render source image, you just need to expose a getter and a setter on 2 metadata of the image, and libtiff, libpng, libjpg used in Skia already have api to do this.
It is not only for writing, but also for reading.
If you load an image with a certain dpi resolution, you need to save/convert it with the same dpi resolution...

I invite you to read this page : https://en.wikipedia.org/wiki/Dots_per_inch

patri… via monorail

unread,
Oct 22, 2021, 3:22:27 AM10/22/21
to bu...@skia.org

Comment #12 on issue 12519 by patri...@gmail.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c12

Skia is awesome and really fast but without this feature it cannot be used as imaging framework in a real life environment (printing, pdf editor, ...). Please reconsider your decision. It is strange that Microsoft SkiaSharp team doesn't push to have this.

bsalo… via monorail

unread,
Oct 26, 2021, 10:20:10 AM10/26/21
to bu...@skia.org
Updates:
Cc: -scro...@google.com bsalo...@google.com djso...@google.com
Owner: scro...@google.com

Comment #13 on issue 12519 by bsalo...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c13


(No comment was entered for this change.)

scro… via monorail

unread,
Oct 26, 2021, 2:06:12 PM10/26/21
to bu...@skia.org

Comment #14 on issue 12519 by scro...@google.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c14

After some more discussion, we think it's reasonable to add APIs to read and write the resolution. It's still low priority, so while I should be able to review patches, I don't plan on working on it anytime soon.

Note that Skia itself won't keep track of the resolution in the image; but we can report it in the SkCodec. Then the client can store it alongside their image and write it in the SkEncoder. (I don't know what SkiaSharp's implementation looks like, so I don't know how that fits it there.)

Another option we discussed would be to allow the client to read "extra" data and they could interpret it themselves. (Benefit: we don't need add Skia code for each feature; it's up to the client to get the specific information they want.) But given that "extra data" might look different in different formats, maybe that's not a clean solution.

patri… via monorail

unread,
Sep 27, 2022, 7:02:07 AM9/27/22
to bu...@skia.org

Comment #15 on issue 12519 by patri...@gmail.com: Get/Set VerticalResolution and HorizontalResolution (DPI) in an image
https://bugs.chromium.org/p/skia/issues/detail?id=12519#c15

Hello,

11 months later, is there any news/plan for this feature ? :)
I really miss this feature to have a kicking performance image load/save in my multiplatform app.

Thanks

Hassan Sabry

unread,
Nov 21, 2023, 12:04:12 PM11/21/23
to Skia Bugs, patri… via monorail, no_r...@monorail-prod.appspotmail.com
Hi Any update on this feature ? is it implemented in current release ?

Techno

unread,
Jun 21, 2024, 5:38:03 AM6/21/24
to Skia Bugs, Hassan Sabry, patri… via monorail, no_r...@monorail-prod.appspotmail.com
Hi,

we use SkiaSharp in .NET for printing in production with png-files and i just stumbled over this issue.
The encoder just sets 72 × 72 dpi as default and so is no way to change that.

Had to fall back on using System.Drawing.Bitmap just to set the final resolution.
So this is my "+1" to get this basic functionality implemented. Thanks!

Jeremy Powell

unread,
Aug 4, 2024, 10:30:54 PM8/4/24
to Skia Bugs
Oh darn, like others here, I've found the same issue. I'm looking to port from System.Drawing.Bitmap to SkiaSharp.SKBitmap, but I need to get/set the DPI when encoding/decoding, and it looks like that info is not provided still.
So, adding my voice to the others here requesting access to that data!

Peter Moore

unread,
Jun 26, 2025, 11:17:33 AMJun 26
to Skia Bugs, Jeremy Powell
Same issue and agree with comments, the absence of this makes it impossible to use Skia as an image procesisng tool.
Reply all
Reply to author
Forward
0 new messages