Partial screenshot & loss of image quality

后端 未结 1 1993
傲寒
傲寒 2021-01-27 06:13

I\'m printing a partial screenshot for camera roll, email, sms, FB, Twitter, etc... Partial screen selected - 100 pixels from top, 100 from bottom.

I used following code

1条回答
  •  温柔的废话
    2021-01-27 06:30

    The problem is that UIGraphicsBeginImageContext() creates an image context with a scale of 1.0, however your layer (as it's being displayed on-screen) has a scale equivalent to the device's screen's scale – which is most likely higher than 1.0.

    You therefore want to be using UIGraphicsBeginImageContextWithOptions() as you correctly said, but instead of passing 2.0 for the scale (which will work on 2x displays, but not on others), pass 0.0.

    As the documentation says for the scale argument:

    The scale factor to apply to the bitmap. If you specify a value of 0.0, the scale factor is set to the scale factor of the device’s main screen.

    The context will therefore automatically detect the scale factor of the screen when you do this, and the image will come out nice and clear on any device you run it on.

    0 讨论(0)
提交回复
热议问题