在ruby+gtk中显示base64加密的图像

2016-12-03 14:06:38来源:网络收集作者:Mark人点击

在ruby+gtk中显示base64加密的图像,有需要的朋友可以参考下。



文档中没有,在网上找了一下午也没找到,受/2014th7cj/d/file/p/20161203/t5r0m1js23y.html 启发,自己编了一个。Gtk比Tk太复杂了。


require 'gtk3'
require 'base64'
icon_encode=< R0lGODlhMAAwAOf/AAABAA0OChYVDRodESslGTosHz8rHTotGkYxITc1KUc2
IVA0IE02IFE1J0s4HE44J1E5JFo3JlM6IF02LlY5JVk6Il05IlE/J107Lls/
H10+JVw+KmA9K2I9JlpAJVlAKmY9LUtGNURLLG0+NW8/MWxBLHFALVtHKmhD
LGBGK2hEMmZGLWdHKG5ENHBFMW5HK2tHNGpJK3ZGOG9JMXpGNGtLMYFEOmdN
MWtMN3JLLnZKNH5HO1JWN3BOL1pUPXpMMXRONo9FQW1RMJFGPYdJQINLOYNL
P3JRN4BNOXxPOY9JPYpLPHlRM45KQo5LSaBHSJxJQplJTIVROJtJR6ZGSp9I
T4ZSPpJORoFUPoNUOX1WOJdNTX5WPplNSIVVNKRKRppORKpMVItXQ5FWRJVV
Ra1NUKpPS4haRI5ZP45YTIpbP7ZNT7FPTaJVSp9XRFtqU1pqWZpZSpNdQ2Bq
WqBZS5dcSq9UVKlWU6tWTpBgRLVUV7dUUrJWUWNtXF5vXZRiQZdhSJ1gSKpc
UrdXXphjTmNyW6dfUZxkRbxZVq5eTpdmSp9jUaViTZxlS6RiU69gVbldV6Jl
TZtoR8RaYL9cX7peXrZgV7VgXaVnT61kVml4YaJqSqxnUr1iVaJrUKtoWLZm
Wmx7ZKlrUqdrWLNoVKxsTr1mXaxtVb1nY3J+YbVrXLNtUbFtV8tmY8ZoYbZv
VLByU8NrYrZwWrpvW8dqaHGEZnaDZsFuXbtwYnWFYrZyYcFvY7N0W7B0ZrJ0
YbpxaLlzXcBwab9yX7x2YMVzZ85wbsF2Z7d6bLl6Z755aHyNadFzcc52cst4
bMd7bLx+cMl6cs94ec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I7vIIw+8ctLLzTbSVJyvMPt+IoojjgRCxhjG6gDCwQuI0Gwmv4zD
zrzctMzNNNM4I00ywggDzL6ciMLIInXUIYYVSZRAYgYlMxSHIao8M844L0sD
88z5DjMMMDefIgomkQRSxxhiSKGDCiRL0BAZdHxyTDZoP/NMMlAnI7XNsrxy
SiSRNEJIHWhYgYX+CysoKwEDDaVRhyO9HLO2Lrgkg4zbUk8NDCtWZw2IHHKc
kYQOL3RAgQQLXOBQGouM4ksvvvgCzDDIND41L6ucUgommwSiiBxoZKHDqURL
wKxDYtQR+iisjCKLLrLwQjUwvJyySimleHKIInmckYUMM6yQAtEMfACRHIEE
sogop0DOS9y8wGK+J55sIskfcqihRRJAwHCDBhAwIDZEZ8jRcySYXH2KJ64r
xSbQd4g//CF6WUjCEYCAgxR4gAEQlMgZxCAHQBAiEp5oRCMwuIlGSEISefgD
GtSQBS1oYQY3uMEHKMAAB6hEIlbIgxxkCIhAAKKAz5uhGqSQBS8c4QfCQDgC
DlbwgQdAIC4ASGJEsKAGK6hBDGqIohqwYIUEagEITPhBDhZ4BCGcYFkHSKIY
y9IQHWSBC1jIghqT8AMgajEHQuiBEGpQgxuk4AQSUMAYxQgRAASAAz9gAhAG
mYMZoOAFMXjBC1Ywgx6kMAUf8IAe96jEPgLAADPIZA9QgIIYeHIFimQBC4Rg
vQ+EkZJkbIgYA4CAFbBgBRAoih8LAIENiPIEBpDlHi0yxgEMAJXA5CNLgklM
qxjzmMhMpjIdEhAAOw==
EOD
Gtk.init
icon=Base64.decode64 icon_encode
#icon相当于File.open("path/to/picture").read
#Gdk::Pixbuf.new 有一个参数data,data 指向内存中的图像数据区。这个数据区应该应该是按照从上
#到下、从左到右排列的像素点数据(不包含图像文件的头),并且每个象素点按照 RGB 的顺序排列(如果
#不是这样,需要首先调整好这些图像数据)。
#要使用File.open("path/to/picture").read读出的数据,需要用Gdk::PixbufLoader把读出的
#数据转换。
loader=Gdk::PixbufLoader.new
loader.write icon
loader.close
pixbuf=loader.pixbuf
img=Gtk::Image.new pixbuf:pixbuf
w=Gtk::Window.new
w.signal_connect("destroy"){Gtk.main_quit}
w.add img
w.show_all
Gtk.main

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台