myQt.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:imagepyqt 作者: Image-Py 项目源码 文件源码
def mkQImage(argb, alpha=None, trans=False):
    """
    Use the cpoied data of ARGB argb to make QImage and return it.
    argb:  (w,h,3 or 4)  this (bgr/rgb or bgra/rgba).
    alpha: ARGB32 if alpha is True else RGB32 (always be 4).
    trans: if trans is true then x/y axes are transposed.

    In default
    Qt: ARGB (32bpp), (width,height)

    """
    if alpha is None or not isinstance(alpha,bool):
        alpha = (argb.shape[2] == 4)

    if argb.shape[2] == 3:
        tmp = np.empty(argb.shape[:2] + (4,), dtype = argb.dtype)
        tmp[...,:3] = argb
        tmp[...,3] = 255
        argb = tmp

    if alpha:
        imgFormat = QtGui.QImage.Format_ARGB32
    else:
        imgFormat = QtGui.QImage.Format_RGB32

    if trans:
        # (y,x,c) => (x,y,c)
        argb = argb.transpose((1, 0, 2))

    addr = argb.data #addr = memoryview(argb)
    qimg = QtGui.QImage(addr,argb.shape[1],argb.shape[0],imgFormat)

    return qimg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号