-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_image_view.cr
More file actions
46 lines (36 loc) · 940 Bytes
/
basic_image_view.cr
File metadata and controls
46 lines (36 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require "../../src/uing"
require "http/client"
require "stumpy_png"
fname = File.join(__DIR__, "crys.png")
canvas = StumpyPNG.read(fname)
width = canvas.width.to_i32
height = canvas.height.to_i32
pixels = Bytes.new(width * height * 4)
(0...height).each do |y|
(0...width).each do |x|
offset = (y * width + x) * 4
r, g, b, a = canvas[x, y].to_rgba
pixels[offset] = r
pixels[offset + 1] = g
pixels[offset + 2] = b
pixels[offset + 3] = a || 255_u8
end
end
UIng.init
window = UIng::Window.new("ImageView Example", 300, 200, margined: true)
window.on_closing do
UIng.quit
true
end
vbox = UIng::Box.new(:vertical)
image = UIng::Image.new(width, height)
image.append(pixels, width, height, width * 4)
image_view = UIng::ImageView.new(image, :fit)
image.free
label = UIng::Label.new(fname)
vbox.append(image_view, stretchy: true)
vbox.append(label)
window.set_child(vbox)
window.show
UIng.main
UIng.uninit