02_photoViewer.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env python
  2. #version : 2024.03.15
  3. #language : ch
  4. #camera : CR5205
  5. import os
  6. from maix import display
  7. from maix import image
  8. from maix import camera
  9. import time
  10. import os
  11. import sys
  12. sys.path.append('/root/')
  13. from CocoPi import BUTTON
  14. key_A = BUTTON(14)
  15. key_B = BUTTON(8)
  16. key_C = BUTTON(13)
  17. key_D = BUTTON(7)
  18. camera.camera.config(size=(320,240))
  19. image.load_freetype("/root/preset/fonts/SourceHanSansCN-Regular.otf")
  20. ###需要查询的文件夹目录及文件格式后缀###
  21. def getImgFileList(filePath="/root/user/img/",selectFile=".jpg"):
  22. import os
  23. FileList=[]
  24. aimFilePath=filePath
  25. aimFile=selectFile
  26. aimFileLenth=len(selectFile)*(-1)
  27. for root,dirs,files in os.walk(aimFilePath):
  28. for name in files:
  29. if str(name)[aimFileLenth:]==aimFile:
  30. FileList.append(name)
  31. return FileList
  32. pngImgShow=getImgFileList()
  33. picNum=len(pngImgShow)
  34. picSelect=0
  35. deleteSig=False
  36. canvas = image.new(size=(320, 240),color = (15,21,46),mode = "RGB")
  37. blackBlock=image.new(size=(320, 24), mode="RGB", color=(0, 0, 0))
  38. while True:
  39. if picNum==0:
  40. canvas.clear()
  41. canvas.draw_string(24, 100, "未找到 .jpg 格式图片!", 1, color=(255, 0, 0))
  42. else:
  43. if key_B.is_pressed():
  44. while key_B.is_pressed():
  45. time.sleep(0.001)
  46. deleteSig=True
  47. os.system("rm /root/user/img/"+pngImgShow[picSelect])
  48. pngImgShow=getImgFileList()
  49. picNum=len(pngImgShow)
  50. else:
  51. if key_D.is_pressed():
  52. while key_D.is_pressed():
  53. time.sleep(0.001)
  54. picSelect=picSelect-1
  55. elif key_C.is_pressed():
  56. while key_C.is_pressed():
  57. time.sleep(0.001)
  58. picSelect=picSelect+1
  59. else:
  60. picSelect=picSelect
  61. if picSelect>picNum-1:
  62. picSelect=0
  63. elif picSelect<0:
  64. picSelect=picNum-1
  65. else:
  66. pass
  67. canvas.clear()
  68. try:
  69. canvas.draw_image((image.open("/root/user/img/"+pngImgShow[picSelect])),0,0)
  70. except:
  71. canvas.draw_string(64, 100, "无法打开此张图片!", 1, color=(255,0, 0))
  72. canvas.draw_string(60, 218, pngImgShow[picSelect], color=(255,255,255), thickness = 1)
  73. canvas.draw_image(image.open("/root/preset/img/blackBlock_7f7f7f_320x24.jpg"), 0, 0,alpha=0.8)
  74. canvas.draw_image(image.open("/root/preset/img/blackBlock_7f7f7f_320x24.jpg"), 0, 216,alpha=0.8)
  75. canvas.draw_image((image.open("/root/preset/img/trashBox_ff0000_24x24.png")).rotate(0, adjust=0),8,216,alpha=1)
  76. canvas.draw_image((image.open("/root/preset/img/exit_ff0000_24x24.png")).rotate(0, adjust=0),288,216,alpha=1)
  77. canvas.draw_image((image.open("/root/preset/img/left_ffffff_16x16.png")).rotate(0, adjust=0),6,4,alpha=1)
  78. canvas.draw_image((image.open("/root/preset/img/left_ffffff_16x16.png")).rotate(180, adjust=0),296,4,alpha=1)
  79. #canvas.draw_image((image.open("/root/preset/img/blackBlock_000000_320x33.png")).rotate(0, adjust=0),0,0,alpha=0.3)
  80. #canvas.draw_string(8, 39+30*demo_j,demoListText[demoSelect] , color=color_white, thickness = 1)
  81. if picNum==0:
  82. canvas.draw_string(116, 3, str(picSelect), color=(255,255,255), thickness = 1)
  83. else:
  84. canvas.draw_string(116, 3, str(picSelect+1), color=(255,255,255), thickness = 1)
  85. canvas.draw_string(160, 3, "/ "+str(picNum), color=(255,255,255), thickness = 1)
  86. display.show(canvas)