2

I'm trying to convert my svg image data to UIImage instance using SVGKit, but when I'm trying to do this its getting crashed, and the error message is like below:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Asked to convert a Percentage value to a different type (5)'

Here is the code for svg to UIImage conversion.

if let data = response.data {
    if let image = SVGKImage(data: data) {
       if let uiImageInstance = image.uiImage {
           self.userImageView.image = uiImageInstance
       }
    }
}

Its getting crashed at this line

->  if let uiImageInstance = image.uiImage {

I'm using AlamofireImage library for downloading my image data from server.

I have checked that my svg data is there in response.

FYI: My image is combination of avatar letters and gradient background.

See below image for reference.

enter image description here

My svg image sample URL: Link

Any help?

Thanks in advance.

Elydasian
  • 2,016
  • 5
  • 23
  • 41
Karthick Selvaraj
  • 2,387
  • 17
  • 28

2 Answers2

2

If you are image is using gradient effect then it will not work in SVGKit. Check whether your image is using any gradient effect.

Apple's rendering DOES NOT ALLOW US to render this image correctly using SVGKFastImageView, because Apple's renderInContext method - according to Apple's docs - ignores Apple's own masking layers. Until Apple fixes this bug, you should use SVGKLayeredImageView for this particular SVG file (or avoid using gradients)

Yogesh Mv
  • 1,041
  • 1
  • 6
  • 12
0

Please do the following:

  1. First of all,check the response.data(is it the correct format you are expecting?)
  2. Try to use image.UIImage instead of image.uiImage
dmp
  • 66
  • 9