python Pil byteio轉換

ShellCollector發表於2019-03-06

 

讀取需要1ms不到,

轉換byteio,BMP17ms,PNG1百多ms,Jpeg需要25ms

這個還能還原回來

from PIL import Image


def a():
    path='d:/1.jpg'
    for i in range(10):
        start=time.time()
        roiImg=Image.open(path)
        read_time=time.time()-start
        start = time.time()
        imgByteArr = io.BytesIO()
        roiImg.save(imgByteArr, format='BMP')
        # roiImg.save(imgByteArr, format='Jpeg')
        # imgByteArr = imgByteArr.getvalue()
        print('pil time',read_time,time.time()-start)
        start = time.time()
        img=Image.open(imgByteArr)
        print('read io time',  time.time() - start)

 

pil time 0.01399993896484375 0.01900196075439453
read io time 0.0
pil time 0.0009675025939941406 0.017029523849487305
read io time 0.0
pil time 0.0 0.018001794815063477
read io time 0.000997781753540039
pil time 0.0 0.017999887466430664
read io time 0.0
pil time 0.0010001659393310547 0.01703047752380371
read io time 0.0010001659393310547
pil time 0.0 0.017999887466430664
read io time 0.0009694099426269531
pil time 0.0 0.019000530242919922
read io time 0.0
pil time 0.0009999275207519531 0.01799941062927246
read io time 0.0
pil time 0.0010330677032470703 0.017968416213989258
read io time 0.0
pil time 0.0009996891021728516 0.018031597137451172
read io time 0.0

相關文章