2017-05-13 35 views
1

正如標題所述,我試圖製作一個腳本來讀取圖像,無關緊要,並將轉換將圖像轉換爲十六進制代碼列表。例如,具有交替白色和黑色像素的8x8 PNG圖像將被轉換爲:試圖使用Imagemagick將RGB圖像轉換爲十六進制代碼列表,每個像素

FFFFFF 
000000 
FFFFFF 
000000 
FFFFFF 
000000 

依此類推。到目前爲止,我已嘗試以下方法:

convert $name.png -compress none pnm:- 

但是,上述代碼僅返回常規數字而非十六進制值。這裏有一個例子:

205 0 0 205 0 0 205 0 0 205 0 0 205 0 0 205 0 0 224 160 0 224 160 0 224 160 0 

出了什麼錯在這裏,我會做它什麼樣的變化,使其輸出的十六進制代碼?

+0

不知道您的個人資料頁面是非常合適的。 –

回答

1

你可以使用ImageMagick的對文件進行解碼,以原始的RGB值和十六進制XXD將它們分組,並顯示:

convert yourImage.png rgb:- | xxd -g3 

我用-g3來組成三個f或RGB文件,如果存在alpha /透明層:

convert yourImage.png rgba:- | xxd -g4 

你可能會喜歡xxd使用其他開關是:

xxd -g3 -c15 # 15 bytes per line, good if you have 5 pixels of 3 bytes each, so hex lines match image scanlines 

xxd -ps   # continuous output without offsets at start of lines