Home>
I'm developing an application with swift, saving png images with UserDefaults and displaying them on multiple screens
When creating an image, I want to reflect it because it is made transparent
I can display it on the screen, but when I read it, the background becomes white without being transparent
Applicable source code
Save
UserDefaults.standard.set (selectedImage! .JpegData (compressionQuality: 1.0), forKey: "imageData")
Read
let imageDate: NSData = UserDefaults.standard.object (forKey: "imageData") as! NSData
selectedFriends.image = UIImage (data: imageDate as Data)
If i put the image in the imageview as it is, the background is transparent, so there is no problem with the image itself
Supplemental information (FW/tool version etc.)Swift version is 5
-
Answer # 1
-
Answer # 2
JPEG format does not have the concept of transparency.
Even if the image is transparent, the transparency information will be lost when converted to JPEG.And
let imageDate: NSData = UserDefaults.standard.object (forKey: "imageData") as! NSData
However,nil
is returned when there is nothing in UserDefaults at the first startup.
Be careful as force cast can fail.
Related articles
- html - no background image is displayed how can i display it?
- ios - [swift] i want to display the image dialog
- html - i want to display a background image when fading in/out the image with slickjs
- java - how to display background image in jsp
- css - how to display the background in the margin in an image file such as a logo
- xcode - i want to display text on top of an image in swift, but i get an exception
- display background image in android studio constraintlayout (repost)
- how to play and display transparent gif and background gif at the same time with wxpython
- swift - when i try to display an image on actionsheet, only a blue square is displayed
- image display using amazon s3 on heroku
- swift - i want to retrieve an image using dkimagepickercontroller
- html - the background image is not displayed
- html - ogp image display on line
- swiftui - i want to display image and text side by side in the header element of section structure of form
- java - i want to display the processed image on the screen
- python - when the transparent image is resized and made transparent with pillow, the background becomes transparent
- javascript - i want to display an image on a canvas and rotate it 90 degrees to the right each time i press a button
- css - i want to display the image size from 0% to 100% without using a mask
- photoshop - make the background color of the artboard transparent
- java - i want to display an image
Trends
Isn't it a problem to extract NSData in JPEG format?
What happens if I extract it in PNG format using pngData ()?