1
let profileImage = UIImage(named:"profile")!
let imageData = profileImage.pngData()

if image size is 680 * 400, now imageData gives 2040 * 1800 or something. how can i make the same size ?

i tried with compression but didn't work

  • 2
    Does this answer your question? [Swift UIImage .jpegData() and .pngData() changes image size](https://stackoverflow.com/questions/70325170/swift-uiimage-jpegdata-and-pngdata-changes-image-size) – Larme Nov 16 '22 at 10:55
  • @Larme No, it doesn't work. i have object of UIImage and convert to png or jpedata() changes the size – SAMIR PATEL Nov 16 '22 at 11:48
  • In the link Larme provided above, Rob says "Your image is apparently 640×480 points with a scale of 2, resulting in 1280×960 pixels. We can either point you to routines to resize, or better, capture the original at a scale of 1. E.g., if capturing with UIGraphicsImageRenderer, specify the scale there, and then no subsequent resizing will be needed." I think this is the reason – Scriptable Nov 16 '22 at 13:40
  • @SAMIRPATEL - what do you mean by *"`imageData` gives 2040 * 1800 or something"*? If I run this: https://pastebin.com/tmbzgED6 -- the output shows matching sizes. – DonMag Nov 16 '22 at 17:08
  • @DonMag may be due to different devices it generates large images – SAMIR PATEL Nov 17 '22 at 05:26
  • @SAMIRPATEL - so... are you saying running that code outputs ***different sizes***? If so, you'll probably need to post a [mre] to get additional debugging help. – DonMag Nov 17 '22 at 13:26

0 Answers0