2017-09-29 57 views
0

我從https://github.com/iconic/open-iconic 下載了一堆圖標圖標最初是黑色的,格式爲.png。集成Kivy標籤和圖標的最佳方法

我想在畫布上添加一個向上的箭頭。

我找到了一種導入圖標的方法,但問題是我無法更改圖標顏色。我可以更改Kivy中的圖標顏色,還是需要爲每種顏色創建一個單獨的.png圖像?

<VitalBoard>: 
canvas: 
    Color: 
     rgba: 0.17, 0.89, 0.89, 1 
     hsv: 0.48, 0.80, 0.34 
    Rectangle: 
     pos: root.width * 2/3 + 20, root.height * 13/24 + 20 
     size: root.width * 2/6 - 10 , root.height * 9/24 - 20 
Label: 
    font_size: 70 
    text: "0" 
    pos: root.width * 2/3 + 20, root.height * 13/24 + 20 
    size: root.width * 2/6 - 10 , root.height * 9/24 - 20 
    Image: 
     source: 'open-iconic/png/arrow-thick-top-8x.png' 
     pos: root.width * 2/3 + 20, root.height * 13/24 + 20 
     size: root.width * 2/6 - 10 , root.height * 9/24 - 20 
     width: 74 
+0

我不認爲你可以在kivy內改變圖像顏色。在將它們加載到kivy之前,您必須在繪製程序中更改它們。 –

回答

1

Kivy對圖像的顏色屬性https://kivy.org/docs/api-kivy.uix.image.html#kivy.uix.image.Image.color

enter image description here

看來,黑色和透明不被它改變。但白色可以改變。

GridLayout: 
    cols:4 
    canvas.before: 
     Color: 
      rgba: [1,1,1,1] 
     Rectangle: 
      pos: self.pos 
      size: self.size 

    Image: 
     source: 'arrow-bottom-8x.png' 
    Image: 
     source: 'arrow-bottom-8x.png' 
     color: [1,0,0,1] 
    Image: 
     source: 'arrow-bottom-8x.png' 
     color: [0,1,0,1] 
    Image: 
     source: 'arrow-bottom-8x.png' 
     color: [0,0,1,1] 
    Image: 
     source: 'download.png' 
    Image: 
     source: 'download.png' 
     color: [1,0,0,1] 
    Image: 
     source: 'download.png' 
     color: [0,1,0,1] 
    Image: 
     source: 'download.png' 
     color: [0,0,1,1] 

我認爲你需要手動或在基維之外。你可能想看看這裏例如https://stackoverflow.com/a/1616893/6646710

+1

這是正確的,顏色用於通過乘法給像素着色,所以當白色(1,1,1,1)被轉換成給定的色調時,黑色(0,0,0,1)僅受影響不透明chanel和透明(X,X,X,0)不會影響唯一重要的chanel,alpha。如果您想爲圖標的黑色部分着色,則可能需要在圖像編輯器中創建一個反轉版本,並在該部分上使用color屬性,並且使用兩個版本來創建顏色組合。 – Tshirtman

+1

這太棒了!由於許多圖標都是黑色的,因此我會使用imagemagick爲未來的觀衆添加此代碼。 '我在'ls * .png';請轉換-negate $ {i%。*}。png results/$ {i%。*}。png;完成' 這會將圖像從黑色翻轉爲白色,以便我們可以使用由PalimPalim提交的代碼 –

相關問題