Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: Vector images from PDF bad quality

for my iOS Swift project I use vectorized pdf files from which Xcode renders the @1x, @2x, @3x images.

Xcode configuration for vectorized PDF file

When I compare the quality of the images generated from PDF with normal PNG images of the same size I see a big difference in the quality between them. Theoretically the quality of the first row and the third row in the following picture should be the same, because a 108x80 image should be rendered and used from my 54x40 PDF on my iPhone 6 with a normal retina display. Unfortunately the quality is far from equal.

enter image description here

Where do these differences come from and maybe how can I increase the quality of the generated images?

like image 345
Philipp Otto Avatar asked Nov 09 '15 15:11

Philipp Otto


2 Answers

I would set the Preserve Vector Data flag on the asset here:

enter image description here

This will make it render as a pdf and scale properly.

like image 156
Iain Smith Avatar answered Sep 28 '22 12:09

Iain Smith


Steps for set a vector image in UIImage :

1 - Convert your svg image to pdf format

2 - Add pdf image to your assets

3 - Select your image and from attribute inspector tab (1.check Preserve Vector Data AND 2.set Scales type in Single Scale)

4 (very important) - Set image name in code and not in storyboard

imgVec.image = UIImage.init(named: "yourImageName")
like image 29
Hamid Reza Ansari Avatar answered Sep 28 '22 12:09

Hamid Reza Ansari