1

I am using the following method to save the PNG image to UserDefaults:

func convertImageToBase64String (img: UIImage) -> String { return img.pngData()?.base64EncodedString() ?? "" } 

The issues are that this data is using significantly Documents & Data storage: enter image description here

And for some reason even if this data is removed from UserDefaults, this amount do not change.

I would like to fix this issues, but need to use PNG images as transparent background is important.

4
  • 1
    Storing images in userDefaults is not recommended. Commented Sep 18, 2022 at 4:47
  • @RameshSanghar how should I store them locally? Commented Sep 18, 2022 at 4:49
  • 1
    Check this : stackoverflow.com/questions/6648518/… Commented Sep 18, 2022 at 4:59
  • No need to use PNG. You can use HEIC which supports transparency as well and it is much lighter. Commented Sep 18, 2022 at 5:17

1 Answer 1

2

After some research, I found out PNG files were not using significant storage. The issue was that original images were being stored in temporary data. I managed to fix this issue following this suggestion: https://stackoverflow.com/a/37043842/14880207

I followed Ramesh Sanghar suggestion as well and stored images in the way he suggested.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.