lv_example_style_6.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from imagetools import get_png_info, open_png
  2. # Register PNG image decoder
  3. decoder = lv.img.decoder_create()
  4. decoder.info_cb = get_png_info
  5. decoder.open_cb = open_png
  6. # Create an image from the png file
  7. try:
  8. with open('../assets/img_cogwheel_argb.png', 'rb') as f:
  9. png_data = f.read()
  10. except:
  11. print("Could not find img_cogwheel_argb.png")
  12. sys.exit()
  13. img_cogwheel_argb = lv.img_dsc_t({
  14. 'data_size': len(png_data),
  15. 'data': png_data
  16. })
  17. #
  18. # Using the Image style properties
  19. #
  20. style = lv.style_t()
  21. style.init()
  22. # Set a background color and a radius
  23. style.set_radius(5)
  24. style.set_bg_opa(lv.OPA.COVER)
  25. style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 3))
  26. style.set_border_width(2)
  27. style.set_border_color(lv.palette_main(lv.PALETTE.BLUE))
  28. style.set_img_recolor(lv.palette_main(lv.PALETTE.BLUE))
  29. style.set_img_recolor_opa(lv.OPA._50)
  30. # style.set_transform_angle(300)
  31. # Create an object with the new style
  32. obj = lv.img(lv.scr_act())
  33. obj.add_style(style, 0)
  34. obj.set_src(img_cogwheel_argb)
  35. obj.center()