How do I blur an image
Asked on 07/31/2024
1 search
To blur an image, you can use SwiftUI's built-in modifiers. Here is an example from the session "Create custom visual effects with SwiftUI" where a blur effect is applied as part of a custom transition:
import SwiftUI
struct ContentView: View {
@State private var isVisible = false
var body: some View {
VStack {
if isVisible {
Image(systemName: "star.fill")
.transition(.blur)
}
Button("Toggle Image") {
withAnimation {
isVisible.toggle()
}
}
}
}
}
extension AnyTransition {
static var blur: AnyTransition {
AnyTransition.modifier(
active: BlurModifier(amount: 20),
identity: BlurModifier(amount: 0)
)
}
}
struct BlurModifier: ViewModifier {
var amount: CGFloat
func body(content: Content) -> some View {
content
.blur(radius: amount)
}
}
In this example, the BlurModifier
is used to apply a blur effect to an image when it appears or disappears. The AnyTransition
extension defines a custom transition that uses this modifier.
For more details, you can refer to the session Create custom visual effects with SwiftUI (11:17).

Use HDR for dynamic image experiences in your app
Discover how to read and write HDR images and process HDR content in your app. Explore the new supported HDR image formats and advanced methods for displaying HDR images. Find out how HDR content can coexist with your user interface — and what to watch out for when adding HDR image support to your app.

Create custom visual effects with SwiftUI
Discover how to create stunning visual effects in SwiftUI. Learn to build unique scroll effects, rich color treatments, and custom transitions. We’ll also explore advanced graphic effects using Metal shaders and custom text rendering.

Build a spatial drawing app with RealityKit
Harness the power of RealityKit through the process of building a spatial drawing app. As you create an eye-catching spatial experience that integrates RealityKit with ARKit and SwiftUI, you’ll explore how resources work in RealityKit and how to use features like low-level mesh and texture APIs to achieve fast updates of the users’ brush strokes.