页次: 1
conky-lua-git for lua5.1 软件在 https://aur.archlinux.org/packages/conky-lua51-git 这里
直接用
require 'cairo_imlib2_helper'
cairo_draw_image('/home/Data/pictres/500px/18.jpg' , cs, 0, 0, 0.2, 0.2)
显示图像 无问题。 于是把 cairo_draw_image函数转为lua代码, 则始终无法绘制(空白无错) 以下是代码 求指教:
require 'cairo'
require 'imlib2'
function conky_images()
if conky_window == nil then return end
local sw = conky_window.width
local sh = conky_window.height
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, sw, sh)
imlib_set_cache_size(4096 * 1024)
local image = imlib_load_image('/home/Data/pictures/A01.jpg')
if image == nil then return end
imlib_context_set_image(image)
local w = imlib_image_get_width()
local h = imlib_image_get_height()
local scaled_w = 0.2 * w
local scaled_h = 0.2 * h
local premul = imlib_create_image(scaled_w, scaled_h)
imlib_context_set_image(premul)
imlib_context_set_color(0, 0, 0, 255)
imlib_image_fill_rectangle(0, 0, scaled_w, scaled_h)
imlib_blend_image_onto_image(image, 0, 0, 0, w, h, 0, 0, scaled_w, scaled_h)
imlib_image_copy_alpha_to_image(image, 0, 0)
# 原c代码是 sizeof(u int) * scaled_w
local cfsw = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, scaled_w)
local result = cairo_image_surface_create_for_data( imlib_image_get_data_for_reading_only(),
CAIRO_FORMAT_ARGB32, scaled_w, scaled_h, cfsw)
local cr = cairo_create(cs);
cairo_set_source_surface(cr, result, 0, 0)
cairo_paint_with_alpha(cr, 0.5)
imlib_context_set_image(image)
imlib_free_image()
imlib_context_set_image(premul)
imlib_free_image()
cairo_destroy(cr)
cairo_surface_destroy(result)
end
最近编辑记录 wxg4net (2013-10-29 10:00:21)
Arch Linux User
离线
页次: 1