Reputation: 1058
I have a png which is partically transparent, namely it has alpha channel. But when I used the following code, the transparent becomes white. I guess the alpha channel is missing. Do you know how to solve this problem? Thank you.
Image("power")
.resizable()
.aspectRatio(contentMode: .fit)
Upvotes: 3
Views: 3224
Reputation: 1058
I used this code to manage to show the transparent effect, but foreground colors are lost.
Color.black
.frame(width: home.screenWidth-2*home.defaultPadding,
height: home.screenWidth)
.mask(Image("power")
.resizable()
.aspectRatio(contentMode: .fit))
Thank you for your helps so much!!!! Without your support, I cann't find the reason.
The compression for the png should be automatic, my project is inherited(basic) somehow, that's why it rendered white.
The code and image has no problem.
Upvotes: 1
Reputation: 564
That's what should happen. You've got an image with an alpha channel over a white background, so you can't see any of the white elements in your image. Change your Color Scheme to dark with .preferredColorScheme(.dark) and you'll see this:
Upvotes: 0