PINRemoteImage
PINRemoteImage copied to clipboard
Better way for decoding image
I'm looking into pin_decodedImageWithData
method and wandering can't we find better way for decoding ? With current implementation in order to decode an image we are creating additional bitmap with the same size and draw on it. We could draw into 1x1 context like done here , concrete implementations are here. If there may be issues with image orientation(in which I'm not sure) we can do this way only when image is in portrait mode. By doing this way we can save temporary memory of image size.
We can set CGContextSetInterpolationQuality
to kCGInterpolationNone
it should be more performant than default one. Here is the documentation link.
There are cases where suggested solution(drawing on 1x1 canvas) will not work correctly. Specifically if we get HEIC encoded image which alpha is not premultiplied we will get wrong decoded image because when compositing layers iOS considers that alpha should be premultiplied. So I think current solution works right, we still can disable interpolation to have better drawing speed.