【问题标题】:Copy and paste in framebuffer复制并粘贴到帧缓冲区中
【发布时间】:2019-11-16 11:13:31
【问题描述】:

我正在帧缓冲区中绘制一个蓝色矩形,我想再次擦除它。在我绘制矩形之前,我复制了将要粘贴矩形的背景,并在 2 秒后将其粘贴到矩形上。矩形不会被删除。

#!/usr/bin/env python

import numpy as np
import time
from PIL import Image
from io import BytesIO

h, w, c = 1024, 1280, 4
fb = np.memmap('/dev/fb0', dtype='uint8',mode='w+', shape=(h,w,c))
x0, y0 = 50, 200
w, h = 300, 400

# Copy backbround:      Does not work?
n0 = fb.read[y0:y0+h, x0:x0+w]

# Paste blue rectangle to framebuffer:      This works.
img = Image.new('RGBA', size=(w, h), color=(255,0,0,255))
n = np.array(img)
fb[y0:y0+h, x0:x0+w] = n

# Erase image:       Does not work?
time.sleep(2)
fb[y0:y0+h, x0:x0+w] = n0

我做错了什么? 如果我将 n0 粘贴到帧缓冲区中的另一个位置,我会得到一个蓝色矩形,而不是黑色矩形。

【问题讨论】:

    标签: python framebuffer


    【解决方案1】:

    我自己用 np.copy 解决了这个问题:

    import numpy as np
    import time
    from PIL import Image
    
    h, w, c = 1024, 1280, 4
    fb = np.memmap('/dev/fb0', dtype='uint8',mode='w+', shape=(h,w,c))
    x0, y0 = 50, 200
    w, h = 300, 400
    
    # Copy background:
    ### n0 = fb.read[y0:y0+h, x0:x0+w]
    n0 = np.copy(fb[y0:y0+h, x0:x0+w])
    
    # Paste blue rectangle to framebuffer:      This works.
    img = Image.new('RGBA', size=(w, h), color=(255,0,0,255))
    n = np.array(img)
    fb[y0:y0+h, x0:x0+w] = n
    
    # Erase image:
    time.sleep(2)
    ### fb[y0:y0+h, x0:x0+w] = n0
    fb[y0:y0+h, x0:x0+w] = np.copy(n0)
    

    【讨论】:

      猜你喜欢
      • 2011-09-27
      • 1970-01-01
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      相关资源
      最近更新 更多