在Swift中反转透明图像的颜色

时间:2019-03-11 18:20:54

标签: swift imageview invert

我已经下载了具有透明背景的图片并将其快速放入“图像视图”中,只是想知道是否有可能将图像的轮廓反转为白色而不是黑色?我的背景是蓝色,这就是它看起来像现在这样的原因。非常感谢大家的帮助!谢谢!

enter image description here

2 个答案:

答案 0 :(得分:1)

声明图像时,请使用以下内容:

Sub test()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim r, r2 As Range, myCol As String
Dim fd As Office.FileDialog
Dim txtFileName As String

Set ws1 = ThisWorkbook.Sheets(1)

Set fd = Application.FileDialog(msoFileDialogFilePicker)
 With fd
      .AllowMultiSelect = False
      .Title = "Please select the file."
      .Filters.Clear
      .Filters.Add "Excel 2003", "*.csv"
      .Filters.Add "All Files", "*.*"
      If .Show = True Then
        txtFileName = .SelectedItems(1) 'replace txtFileName with your textbox
      End If
End With

Application.Workbooks.Open txtFileName
Set ws2 = ActiveWorkbook.Sheets(1)
ThisWorkbook.Activate

With CreateObject("VBScript.RegExp")
    .Pattern = "^([a-z]|[a-h][a-z]|[a-i][a-v])$"
    .IgnoreCase = True
    Do
        myCol = InputBox("Enter Column")
    Loop While Not .test(myCol)
End With

With CreateObject("Scripting.Dictionary")
    .comparemode = vbTextCompare
    For Each r In ws1.Range(myCol & "37", ws1.Range(myCol & Rows.Count).End(xlUp))
        If IsEmpty(r) = False Then
            For Each r2 In ws2.Range("c2", ws2.Range("c" & Rows.Count).End(xlUp))
                If r2.Value = r.Value Then
                    ws2.Cells(r2.Row, 2).Copy
                    ws1.Cells(r.Row, 3).PasteSpecial xlValues
                    Exit For
                End If
            Next r2
        End If
    Next r
End With

Set ws1 = Nothing: Set ws2 = Nothing

End Sub

这是您要寻找的选项: https://developer.apple.com/documentation/uikit/uiimagerenderingmode/uiimagerenderingmodealwaystemplate?language=objc

答案 1 :(得分:0)

要反转图像视图的image属性的颜色,请使用以下命令:

let startImage = CIImage(image: yourImageView.image!)

if let filter = CIFilter(name: "CIColorInvert") {
    filter.setValue(startImage, forKey: kCIInputImageKey)
    let newImage = UIImage(CIImage: filter.outputImage!)
    yourImageView.image = newImage
}