I’ve requirement to load an commercial picture in my app and these are often logos of firms.
The factor about logos is that whereas they are often of a particular peak, their width would change.
So I began with a quite simple answer, I uploaded a 90 x 20 png picture in Firebase storage after which used the simples code:
Picture(uiImage: picture)
and this rendered the rendered the picture at 90 x 20.
Some particulars ignored is that I make a community request within the background to obtain this picture after which – I really feel this is likely to be not related however can add code if wanted.
The problem is that on an iPhone 16 (common and professional) machine, these picture get actually blurry.
So what I did was add a 3x picture however that earlier code made the picture develop massively as now the picture dimensions had been 270 x 60.
So to render the prime quality picture on the earlier dimensions, I did the next:
Picture(uiImage: picture)
.resizable()
.renderingMode(.template)
.scaledToFit()
.body(peak: 20)
// The width of the mother or father view internet hosting this had a max width of infinity
Now this labored and the pictures had been sharper. The problem with specifying a hardcoded peak of 20, we bumped into the difficulty with some firm’s logos being a bit taller so then we got here up with a rule the place the max peak of the emblem must be 28 so:
- If I add 90 x 20, the pictures peak can be 20
- If I uploaded 360 x 80, the picture peak can be 28
I obtain this through:
Picture(uiImage: picture)
.resizable()
.renderingMode(.template)
.tint(Constants.Colours.brand)
.scaledToFit()
.body(peak: min(picture.dimension.peak, 28))
This works for a lot of the use circumstances, nevertheless, if I need a picture to render at 90 x 20 however at a top quality, and if I add a picture at 3x 270 x 60, it could not render at 90 x 20 however fairly at 126 x 28 as a result of 28 is the max peak
Whereas this is likely to be acceptable, what can be a great way to render the 2x and 3x photographs at its authentic dimension fairly than making the picture develop to the 28 max peak.