# blend mode

[SwiftUI](/ios/swiftui.md) ⟩ [view](/ios/swiftui/view.md) ⟩ [drawing](/ios/swiftui/view/drawing.md) ⟩ blend mode

{% tabs %}
{% tab title="🔸 定義" %}
{% hint style="info" %}

* <mark style="color:red;">**source**</mark> - view that comes with the blending effect.
* <mark style="color:red;">**destination**</mark> - everything underneath that view.
  {% endhint %}

```swift
source     : pixels being applied (blend modes)
destination: pixels already stored to the context

R : result of blend operation
S : source pixel values
Sa: source alpha
D : destination pixel values
Da: destination alpha

// blend modes:
R = S × Sa + D × (1 – Sa)      // normal
R = S × Da                     // source in
R = S × (1 – Da)               // source out
R = S × Da + D × (1 – Sa)      // source atop (?)
R = S × (1 – Da) + D           // destination over
R = D × Sa                     // destination in
R = D × (1 – Sa)               // destination out
R = S × Da + D × (1 – Sa)      // destination atop (?)
```

{% endtab %}

{% tab title="💈範例" %}

* [.destinationOut](/ios/swiftui/view/drawing/blend-mode/.destinationout.md) - 挖洞用的效果。
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] 5 Star ⟩ [SwiftUI Blend Modes](https://www.fivestars.blog/articles/swiftui-blend-modes/)
* [ ] Design+Code ⟩ [Shape, Stroke and Blend Mode](https://designcode.io/swiftui-ios15-shape-stroke-blend-mode)
* [ ] Erica Sadun ⟩ iOS Drawing
* [ ] 彼得潘 ⟩ [SwiftUI 生動有趣的圖片效果 modifier](https://medium.com/彼得潘的-swift-ios-app-開發問題解答集/swiftui-生動有趣的圖片效果-modifier-80d275c3ec0f) - .colorMultiply() ...
* [ ] [The Science of All 27 Blend Modes in Photoshop](https://youtu.be/i1D9ijh3_-I) (YouTube)
  {% endtab %}

{% tab title="📘 手冊" %}

* View ⟩ [Graphics and Rendering](https://developer.apple.com/documentation/swiftui/view-graphics-and-rendering)
  * [BlendMode](https://developer.apple.com/documentation/swiftui/blendmode) (<mark style="color:red;">**enum**</mark>)
  * [.blendMode(\_:)](https://developer.apple.com/documentation/swiftui/view/blendmode\(_:\))
  * [.compositingGroup()](https://developer.apple.com/documentation/swiftui/view/compositinggroup\(\))
  * [Appearance](https://developer.apple.com/documentation/swiftui/view-appearance)
    * [.overlay(alignment:content:)](https://developer.apple.com/documentation/swiftui/view/overlay\(alignment:content:\))
* [GraphicsContext](https://developer.apple.com/documentation/swiftui/graphicscontext) ⟩ [GraphicsContext.BlendMode](https://developer.apple.com/documentation/swiftui/graphicscontext/blendmode-swift.struct)  ⭐️
* [Core Image](https://developer.apple.com/documentation/coreimage) ⟩ [CIBlendKernel](https://developer.apple.com/documentation/coreimage/ciblendkernel) - ⭐️ 有每個混合模式的圖例 (但為何稱為 blend kernel❓)
* SwiftOnTap ⟩ View ⟩ [.colorMultiply(\_:)](https://swiftontap.com/view/colormultiply\(_:\))
  {% endtab %}

{% tab title="👥 相關" %}

* [view.shadow()](/ios/swiftui/view/drawing/shadow/view.shadow.md)
* [view.inverseMask()](/ios/custom/ext/view/.inversemask.md)
* [mask](/ios/swiftui/view/drawing/mask.md)
  {% endtab %}

{% tab title="🗣 討論" %}

* [How can I clip a Shape with another Shape in SwiftUI?](https://stackoverflow.com/a/67128123/5409815)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/ios/swiftui/view/drawing/blend-mode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
