從文件中恢復jpg

代碼:


import re
 
fp = open('Image.raw', 'rb')
content = fp.read()
fp.close()
 
cnt = 0
start = 0
while True:
    pic_start = content.find('\xff\xd8\xff\xe0', start)
    if pic_start == -1:
        break
    start = pic_start + 1
    while True:
        first_start = content.find('\xff\xd8\xff\xe0', start)
        first_end = content.find('\xff\xd9', start)
        if first_start != -1 and first_start < first_end:
            start = first_end + 1
        else:
            break
    pic_end = first_end
     
    cnt += 1
    fp = open('%d.jpg' % cnt, 'wb')
    fp.write(content[pic_start:pic_end + 2])
    fp.close()
    start = pic_end + 1

轉載自:ZXCVBNM《
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章